I\'m trying to move selected items in list box1 to list box2, and vice versa. I have two buttons, >> and <<. When I select items in lis
There will be conflicts for every deleted row, so go with the below code:
>>
for (int intCount = ListBox1.SelectedItems.Count - 1; intCount >= 0; intCount--)
{
ListBox2.Items.Add(ListBox1.SelectedItems[intCount]);
ListBox1.Items.Remove(ListBox1.SelectedItems[intCount]);
}
<<
for (int intCount = ListBox2.SelectedItems.Count - 1; intCount >= 0; intCount--)
{
ListBox1.Items.Add(ListBox2.SelectedItems[intCount]);
ListBox2.Items.Remove(ListBox2.SelectedItems[intCount]);
}
If the above one doesn't work then try this:
while (ListBox1.SelectedItems.Count > 0)
{
ListBox2.Items.Add(ListBox1.SelectedItems[0].Text);
ListBox1.SelectedItems[0].Remove();
}
For more type of answers you can go with this link