简体   繁体   中英

how to print the checked items from the checked listbox to a label in c#?

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?

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:

  • Where boundPropertyNameHere be the name of property that used to bind the collection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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