In this article, We’ ll provide to move the multiple selected items from ListBox1 to ListBox2, when you click the Move Button.
Step1: Form Design (2xListbox, 1xButton)
Step 2: Set Selection Mode of Listbox1 and ListBox2.
1 2 3 4 5 6 7 | private void Form1_Load(object sender, EventArgs e) { listBox1.SelectionMode = SelectionMode.MultiSimple; listBox2.SelectionMode = SelectionMode.MultiSimple; } |
Step 3: Move selected items From Listbox1 to ListBox2.
1 2 3 4 5 6 7 8 9 10 11 12 | private void btnMove_Click(object sender, EventArgs e) { for (int i = listBox1.SelectedIndices.Count - 1; i >= 0; i--) { //add item to listbox2. listBox2.Items.Add(listBox1.SelectedItems[i]); //remove selected item from listbox1 listBox1.Items.RemoveAt(listBox1.SelectedIndices[i]); } } |