SpankySpanky
Programmer
Hello all
I am having problems with a CheckedListBox, I am trying to use the SelectedIndexChanged event to detect when the user toggles the check box. I have the CheckOnClick property set to True so that the check is toggled when anywhere on the selected line is clicked.
The problem is that when I click quickly multiple times the check toggles but I dont always get an event fired. It works fine if I click slowly but I cant guarantee what the user will do.
The problem can be replicated if you create a new project with a CheckedListBox and two labels, turn on CheckOnClick for the CLB and paste in the following code:
'==================================================
Dim a As Integer=0, b As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
CheckedListBox1.Items.Add("TestItem")
End Sub
Private Sub CheckedListBox1_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles CheckedListBox1.SelectedIndexChanged
a += 1
Label1.Text = CStr(a)
End Sub
Private Sub CheckedListBox1_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles CheckedListBox1.MouseUp
b += 1
Label2.Text = CStr(b)
End Sub
'==================================================
The two labels count how many SelectedIndexChanged and MouseUp events have occured. When you click the TestItem, the check box toggles normally, and the events both count up normally. However when you click fast, the checkbox still toggles but the SelectedIndexChanged event trips only on some of the checkbox changes. MouseUp always trips as expected.
This seems like a bug to me... but only because I cant see what else I did wrong. I thought it might have to do with doubleclicking because there appears to be only half the events triggered, but still why is the checkbox toggling? Surely the number of events should track the checkbox...
I dont know what to do....
Any ideas? Anybody?
I am having problems with a CheckedListBox, I am trying to use the SelectedIndexChanged event to detect when the user toggles the check box. I have the CheckOnClick property set to True so that the check is toggled when anywhere on the selected line is clicked.
The problem is that when I click quickly multiple times the check toggles but I dont always get an event fired. It works fine if I click slowly but I cant guarantee what the user will do.
The problem can be replicated if you create a new project with a CheckedListBox and two labels, turn on CheckOnClick for the CLB and paste in the following code:
'==================================================
Dim a As Integer=0, b As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
CheckedListBox1.Items.Add("TestItem")
End Sub
Private Sub CheckedListBox1_SelectedIndexChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles CheckedListBox1.SelectedIndexChanged
a += 1
Label1.Text = CStr(a)
End Sub
Private Sub CheckedListBox1_MouseUp(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) Handles CheckedListBox1.MouseUp
b += 1
Label2.Text = CStr(b)
End Sub
'==================================================
The two labels count how many SelectedIndexChanged and MouseUp events have occured. When you click the TestItem, the check box toggles normally, and the events both count up normally. However when you click fast, the checkbox still toggles but the SelectedIndexChanged event trips only on some of the checkbox changes. MouseUp always trips as expected.
This seems like a bug to me... but only because I cant see what else I did wrong. I thought it might have to do with doubleclicking because there appears to be only half the events triggered, but still why is the checkbox toggling? Surely the number of events should track the checkbox...
I dont know what to do....
Any ideas? Anybody?