Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loop through checkedListBox items without the select all item

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

like image 789
Paradigm Avatar asked Nov 17 '25 00:11

Paradigm


2 Answers

Try:

foreach (var s in checkedListBoxDepts.CheckedItems)
{
      if (checkedListBoxDepts.IndexOf(s) == 0)
          continue;
      list.Add(s.ToString());
}
like image 98
Andrey Gordeev Avatar answered Nov 19 '25 13:11

Andrey Gordeev


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);
like image 41
faraaz Avatar answered Nov 19 '25 12:11

faraaz