c# - CheckedListBox throwing argument out of range when it shouldn't -


this .net 3.5 winforms project.

i'm having weird error trying programmatically check checkboxes in checkboxlist.

for (int = 0; < 5; i++) {     cblistforming.items.add((i + 1).tostring());     cblistforming.setitemchecked(i, true); } 

so adds 5 items, 1 5, , have added checkboxes checked default. nothing surprising.

on first iteration of loop, works fine on second iteration (i == 1), setitemchecked throws exception.

system.argumentoutofrange {"index out of range. must non-negative , less size of collection.\r\nparameter name: index"}

i can see first checkbox checked visually well. rest of them aren't because of above exception.

this pretty baffling. testing purposes, tried add items first, , programmatically check them later second loop, still same issue happens, even though count of checkbox 5.

i tried using setitemcheckstate instead. again, same issue.

i think might've broken checkedlistbox component itself, or weird framework bug i've encountered.

any insights what's going on here appreciated.

try following:

for (int = 0; < 5; i++) {     cblistforming.items.add((i + 1).tostring(), true); } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -