0

I m using VS2010 with SQL server 2008 at the backend. I m creating a windows application in which I have 2 listboxes.the data is being retrieved from SQL server database in listbox1.i want to select all itms from this listbox1 and add them to listbox2. And remove itms from this listbox2 and add them to listbox1.

4
Contributors
3
Replies
19
Views
2 Years
Discussion Span
Last Post by Sulaiman_1
0
listBox1.Items.Clear(); // for removing all items



   foreach(ListItem listItem in listBox1.Items) /* adding items to another listbox*/
    {
       if (listItem.Selected == True)
       {
          listBox2.Items.Add(listItem);
       }
    }

Edited by castajiz_2: swfas

0

What would be wrong, to first copy Listbox2 to Listbox1 and then fetch data from DB to Listbox2?

0
//adding all items from listbox1 to listbox2
            foreach (string temp in listBox1.Items)
                listBox2.Items.Add(temp);

//after you removed data, the below code will help you to regenarate the listbox1
            listBox1.Items.Clear();
            foreach (string temp in listBox2.Items)
                listBox1.Items.Add(temp);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.