vb.net 2005: can't get checklistbox items to check/uncheck
Posted on 2008-10-18
I use the following code to load a CBL with a list of files, each of which the user should be able to check/uncheck:
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For Each file As String In Directory.GetFiles(path, "*.txt")
If (Not file.EndsWith("xxx.txt")) Then
clb1.Items.Add(file.Substring(file.LastIndexOf("\") + 1), False)
The following code allows the user to check an item, but does not allow unchecking. GetItemChecked seems to return false even after the item is checked. Any help? I'm surprised I am writing any code, I thought the list would have supported checking/unchecking by default.
Private Sub clb1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clb1.SelectedIndexChanged
If (clb1.SelectedIndex <> -1) Then
If (clb1.GetItemChecked(clb1.SelectedIndex)) Then
Thanks for any help.