繁体   English   中英

将选定的项目从清单框移动到清单框C#

[英]move the selected items from checkedlistbox to listbox C#

我正在尝试将选定的项目从清单框移动到清单框。但是我不能...

for (int x = 0; x<=checkedListBox1.Items.Count;x++ )
{
    if (checkedListBox1.GetItemChecked(x))
    {
        listBox1.Items.Add(checkedListBox1.SelectedItem + "\r\n");
    }
}

请帮我

下面的代码将选择的项目添加到listBox1并将其从checkedListBox1删除,但是SelectedItems每次都是一个项目,因为CheckedListBox不支持多选,因此可以使用CheckedItems而不是SelectedItems选择多个项目。

// Add Selected Items to ListBox
listBox1.Items.AddRange(checkedListBox1.SelectedItems.OfType<object>().ToArray());

// Remove from  CheckedListBox
foreach (var item in checkedListBox1.SelectedItems.OfType<object>().ToList())
{
    checkedListBox1.Items.Remove(item);
}

暂无
暂无

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

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