HI Guys,
Suppose I am having two list boxes one is source and another one is destination.
from source I have to select an item once we click on button the particular item will have to switch on another listBox which is destination.
So how can I do this.
Please guided me.
Loading
Kirtan PatelPosted Jan 12, 2010, 1:41 AM
Here is your Solution :)
please check "do you like this answer" check box :-) it helps me :-)
Code fore >> Button
-------------------
private void button1_Click(object sender, EventArgs e)
{
try
{
string SelectedItem = listBox1.SelectedItem.ToString();
int index_of_SelectedItem = listBox1.SelectedIndex;
//Delete it From ListBox 1 and Copy it To List Box 2
listBox1.Items.RemoveAt(index_of_SelectedItem);
listBox2.Items.Add(SelectedItem);
}
catch
{
MessageBox.Show("Please Select the Item First");
}
}
Code for << Button
-----------------------
private void button2_Click(object sender, EventArgs e)
{
try
{
string SelectedItem = listBox2.SelectedItem.ToString();
int index_of_SelectedItem = listBox2.SelectedIndex;
//Delete it From ListBox 2 and Copy it To List Box 1
listBox2.Items.RemoveAt(index_of_SelectedItem);
listBox1.Items.Add(SelectedItem);
}
catch
{
MessageBox.Show("Please Select the Item First");
}
}