Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,081 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,560 people online right now. Registration is fast and FREE... Join Now!




How can i remove the selected data from the listbox after transfering

 
Reply to this topicStart new topic

How can i remove the selected data from the listbox after transfering, which is the first listbox which i am binded through data source

VaibhavCool
15 Apr, 2008 - 11:52 PM
Post #1

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 2

CODE
int count = lbUserPrivilegeList.SelectedItems.Count;
                arrSelectedValue = new int[count];
                DataSet dsUserPrivilege = new DataSet();
                int index = 0;
                foreach (DataRowView datarow in lbUserPrivilegeList.SelectedItems)
                {
                    //UserRoleId = Convert.ToInt32(cmbUserRole.SelectedValue);
                    //arrSelectedValue[index] = Convert.ToInt32(datarow.Row.ItemArray[0]);
                    lbUserSelectedPrivilegeList.Items.Add(datarow.Row.ItemArray[1]);
                    
                    //index++;
                }
                for (int iRetValue = count - 1; iRetValue >= 0; iRetValue--)
                {
                    lbUserPrivilegeList.Items.Remove(lbUserPrivilegeList.SelectedItems[iRetValue]);
                }
                   //lbUserPrivilegeList.Items.Remove();
                   //dsUserPrivilege.Tables[0].Rows[0].Delete();
              
                     lbUserPrivilegeList.ClearSelected();

User is offlineProfile CardPM
+Quote Post

skaoth
RE: How Can I Remove The Selected Data From The Listbox After Transfering
16 Apr, 2008 - 09:14 AM
Post #2

D.I.C Regular
Group Icon

Joined: 7 Nov, 2007
Posts: 342



Thanked: 10 times
Dream Kudos: 100
My Contributions
Removing an item from a listbox is just the reverse of adding them

CODE

// If all you need to do is remove the item from the listbox this should work
foreach (int i in listBox1.SelectedIndices)
{
    object itemToRemove = listBox1.Items[i];
    listBox1.Items.Remove(itemToRemove);
}


If this isn't what you want please explain a little better
User is online!Profile CardPM
+Quote Post

Jayman
RE: How Can I Remove The Selected Data From The Listbox After Transfering
16 Apr, 2008 - 03:04 PM
Post #3

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,919



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
If I am understanding your question correctly, you want to remove it from the Databound ListBox. Is that correct?

Also, don't post your question in the topic description, put it in the post itself.
User is offlineProfile CardPM
+Quote Post

VaibhavCool
RE: How Can I Remove The Selected Data From The Listbox After Transfering
16 Apr, 2008 - 09:51 PM
Post #4

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 2

QUOTE(jayman9 @ 16 Apr, 2008 - 04:04 PM) *

If I am understanding your question correctly, you want to remove it from the Databound ListBox. Is that correct?

Also, don't post your question in the topic description, put it in the post itself.



what u have understood is correct. Can you please guide me how can i do it...
User is offlineProfile CardPM
+Quote Post

Jayman
RE: How Can I Remove The Selected Data From The Listbox After Transfering
17 Apr, 2008 - 08:32 AM
Post #5

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,919



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
You cannot remove it from a DataBound object, at least not without first removing it from the datasource.

You will simply need to populate the Listbox with the data without binding it to the datasource and then you can remove an item from the list without problem.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:43PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month