I did this using the CopyTo method to copy elements into an array along the length of the count of selected elements, and then looped around this array, removing each corresponding element from ListBox1.
private void button1_Click(object sender, EventArgs e) { object[] itemsToRemove = new object[listBox1.SelectedItems.Count]; listBox1.SelectedItems.CopyTo(itemsToRemove, 0); foreach (object item in itemsToRemove) { listBox1.Items.Remove(item); listBox2.Items.Add(item); } }
source share