hi!
i take Two list boxes. and two buttons one for Add Items and another for Remove Items.
by default items is displayed in Listbox1 and i select items (one or more) and click Add items button that selected items are added into the Listbox2 . And i select items into the Listbox2, and i click Remove Items button That selected items are Removed from Listbox2.
Please Give a code for this
Thanks.
One of the listbox data is transfer to another listbox
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Jaish MathewsRank #225 · 11K reputationPosted Apr 17, 2010, 9:07 AM EDT
I have only string tyes in my listbox and below code works for me
private void addButton_Click(object sender, EventArgs e)
{
//Adding to 2nd listbox
foreach (string item in listBox1.SelectedItems)
{
listBox2.Items.Add(item);
}
//Removing from 1st list box, items which added to 2nd list box
foreach (string item in listBox2.Items)
{
listBox1.Items.Remove(item);
}
}
private void button1_Click_1(object sender, EventArgs e)
{
//Adding to 1st listbox, items which selected in 2nd listbox
foreach (string item in listBox2.SelectedItems)
{
listBox1.Items.Add(item);
}
//Removing from 2nd list box, items selected
foreach (string item in listBox1.Items)
{
listBox2.Items.Remove(item);
}
}
ajay rajuRank #4,639 · 333 reputationPosted Apr 19, 2010, 9:55 PM EDT