Reputation: 172
I'm Trying to fetch items from checked listbox when the user checks the listbox item it should be displayed in a label on a button click. I tried using this:
foreach (object item in checkedlistbox1.CheckedItems)
{
labelto.Text += checkedlistbox1.SelectedItem.ToString();
}
But I'm getting this exception:
List that this enumerator is bound to has been found, enumerator can only be used if the list does not change.
How to print the checked items from the checked listbox to a label?
Upvotes: -1
Views: 864
Reputation: 29036
This is not a complicated task, why don't you make try with the following:
string displayText = "";
foreach(object item in checkedListBox1.CheckedItems)
{
DataRowView castedItem = item as DataRowView;
displayText += castedItem["boundPropertyNameHere"];
}
labelto.Text = displayText;
Please note:
boundPropertyNameHere
be the name of property that used to bind the collection.Upvotes: 0