Domanda

Im having some problems. I have a checkedlistbox with some 40 names. I want to add the names that are checked to a new list. I seem to have problems with the for and if loop for this. Help anyone?

È stato utile?

Soluzione

If I understand you correctly, it seems that there might already be a method of CheckedListBox for this: http://msdn.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.checkeditems.aspx

You can then iterate through that Collection to do what ever you want like:

foreach(object itemChecked in checkedListBox1.CheckedItems) {
    //Deal with each itemChecked object
}

or just cast straight to a List

List<SomeTypeUsedForTheItems> checkedItems = checkedListBox1.CheckedItems.Cast<SomeTypeUsedForTheItems>().ToList()
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top