Friday, February 4, 2011

Guide: How to Clear Checked Items from a Checked List Box (C#)

If you've ever played with checked list boxes before, you know that even though the ClearSelected() method clears the underlying selections, it does not remove the visual checks in the checkboxes on the page. To the user, the control still looks 'checked.'

checkedListBoxWorkPerformed.ClearSelected();


You can fix this issue by adding a short loop:



                for (int i = 0; i <= (checkedListBoxWorkPerformed.Items.Count - 1); i++)
                {
                    checkedListBoxWorkPerformed.SetItemChecked(i, false);
                }

The ClearSelected() method will clear the underlying values, and this loop will clear the graphical 'checks.'

No comments:

Post a Comment