繁体   English   中英

将项目从一个listBox移动到另一个listBox

[英]Move item from one listBox to another listBox

我需要将项目从一个ListBox移动到另一个ListBox。 将它们添加到第二个可以工作,但我想移动多个选定的项目。

private void btnMove_Click(object sender, EventArgs e)
{
    if (listBox2.SelectedItem != null)
    {
       listBox3.Items.Add(listBox2.SelectedItem);
       listBox2.Items.Remove(listBox2.SelectedItem);
    }
}

我的问题是这个移动项目一个接一个,但我需要一次移动多个选定的项目。

  private void Button1_Click(object sender, EventArgs e)

    {
        if (listBox1.SelectedItem != null)
        {
            while (listBox1.SelectedItems.Count > 0)
            {
                listBox2.Items.Add(listBox1.SelectedItem);
                listBox1.Items.Remove(listBox1.SelectedItem);
            }
        }
        else
        {
            MessageBox.Show("No item selected");
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM