vb.netchecklistbox

Clear checklist in vb.net


I am trying to write code for my reset button in vb. I have used the following:

chlstAddIn.ClearSelected();

But it only clears the highlighting, not the checkbox itself.


Solution

  • Select and Check are two different concepts in the checkedlistbox. ClearSelected will not uncheck the items. To uncheck all items that are checked, use SetItemCheckState. This is what i would do in c#.

    foreach (int i in chlstAddIn.CheckedIndices)
    {
    chlstAddIn.SetItemCheckState(i, CheckState.Unchecked);
    }
    

    In VB, use this code in reset button click event,

    For Each i As Integer In chlstAddIn.CheckedIndices
      chlstAddIn.SetItemCheckState(i, CheckState.Unchecked)
    Next