[英]How to move multiple selected item from one listbox to another 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.