Try:
foreach (var s in checkedListBoxDepts.CheckedItems)
{
if (checkedListBoxDepts.IndexOf(s) == 0)
continue;
list.Add(s.ToString());
}
Domanda
I want to get the items from a checkedListBox
into a List<>
, but without the select all/ deselect all (first checkbox)..can't figure it out how to not add the first item..
this is the code:
foreach (string s in checkedListBoxDepts.CheckedItems)
{
if (checkedListBoxDepts.SelectedItems.IndexOf(s) == 0)
continue;
list.Add(s);
}
then I take the items and put in another list to avoid errors:
foreach (string s in list)
{
list2.Add(s);
}
but still the select all is loaded...help
Soluzione
Try:
foreach (var s in checkedListBoxDepts.CheckedItems)
{
if (checkedListBoxDepts.IndexOf(s) == 0)
continue;
list.Add(s.ToString());
}
Altri suggerimenti
foreach (string s in checkedListBoxDepts.CheckedItems)
{
if (checkedListBoxDepts.SelectedItems.IndexOf(s) == 0)
continue;
list.Add(s);
}
after that remove first item from list
list.removeat(0);