hi
I would like to make a code where I can move items from listbox1 to other listbox2 using the button1(as moving the item to listbox2) and button2(as moving the item to listbox1).
I would like that before I click on the items in my listbox1, the button1 will be disabled or grayed out. And the same with my button2.
I already figured out the button1 to work but the button2 seems I have to add something which I'm not sure. Could you please check my code why I'm stuck up? Thanks
Here is the code:
private void btnToRight_Click(object sender, EventArgs e)
{
if (listBox1.SelectedItem != null)
{
listBox2.Items.Add(listBox1.SelectedItem);
listBox1.Items.Remove(listBox1.SelectedItem);
btnToRight.Enabled = false;
}
}
private void btnToLeft_Click(object sender, EventArgs e)
{
if (listBox2.SelectedItem != null)
{
listBox1.Items.Add(listBox2.SelectedItem);
listBox2.Items.Remove(listBox2.SelectedItem);
btnToLeft.Enabled = false;
}
}
private void listBox1_Leave(object sender, EventArgs e)
{
if (listBox1.SelectedItem == null)
{
btnToRight.Enabled = false;
}
else
{
btnToRight.Enabled = true;
}
}
private void listBox2_Leave(object sender, EventArgs e)
{
if (listBox2.SelectedItem == null)
{
btnToLeft.Enabled = false;
}
else
{
btnToLeft.Enabled = true;
}
}