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 listbox1 and then click on >>
the items should move from listbox1 to listbox2.
private void MoveListBoxItems(ListBox source, ListBox destination)
{
ListBox.SelectedObjectCollection sourceItems = source.SelectedItems;
foreach (var item in sourceItems)
{
destination.Items.Add(item);
}
while (source.SelectedItems.Count > 0)
{
source.Items.Remove(source.SelectedItems[0]);
}
}
private void button2_Click_1(object sender, EventArgs e)
{
MoveListBoxItems(listbox , lstActivity);
}
your code works fine. i tested it. your question is "I try to move selected item in list box1 to list box2."
i think your button2 has problem.delete button2 and the code below
then create other button and create click event.
full source:
this code is work. if you want select more than one item change property SelectionMode = MultiSimple;
There will be conflicts for every deleted row, so go with the below code:
>>
<<
If the above one doesn't work then try this:
For more type of answers you can go with this link
I solved using this code:
Here Two ListBoxes. When i select the name from Left listbox and click ">>" Button the data move to Right ListBox
Code.. currentItemText = LeftListBox.SelectedValue.ToString(); currentItemIndex = LeftListBox.SelectedIndex;
Get the >> and << buttons created with 2 list boxes like listbox2 and 3 below...get ur items in list box 2 first by something like get-content or get-adcomputer etc..