Move selected items from one listbox to another in C# winform

前端 未结 7 1557
闹比i
闹比i 2020-12-06 02:41

I\'m trying to move selected items in list box1 to list box2, and vice versa. I have two buttons, >> and <<. When I select items in lis

相关标签:
7条回答
  • 2020-12-06 03:29
    private void buttonMoveToListBox1_Click(object sender, EventArgs e)
    {
        if(listBox1.SelectedIndex != -1)
        {
            listBox2.Items.Add(listBox1.SelectedValue);
            listBox1.Items.Remove(listBox1.SelectedValue);
        }
    }
    
    private void buttonMoveToListBox2_Click(object sender, EventArgs e)
    {
        if(listBox2.SelectedIndex != -1)
        {
            listBox1.Items.Add(listBox2.SelectedValue);
            listBox2.Items.Remove(listBox2.SelectedValue);
        }
    }
    
    0 讨论(0)
提交回复
热议问题