[英]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.