我正在尝试从检查列表框中获取项目,当用户检查列表框项目时,它应该在按钮单击的标签中显示。我试过用这个:
foreach (object item in checkedlistbox1.CheckedItems)
{
labelto.Text += checkedlistbox1.SelectedItem.ToString();
}
但我得到了这个例外:
List that this enumerator is bound to has been found, enumerator can only be used if the list does not change.
如何将选中的项目从选中的列表框打印到标签?
这不是一项复杂的任务,为什么不试试以下内容:
string displayText = "";
foreach(object item in checkedListBox1.CheckedItems)
{
DataRowView castedItem = item as DataRowView;
displayText += castedItem["boundPropertyNameHere"];
}
labelto.Text = displayText;
请注意:
boundPropertyNameHere
是用于绑定集合的属性的名称。