Reputation: 197
According to Microsoft: "In Visual Basic 6.0, the Click event is raised when the CheckBox state is changed programmatically. " and this is exactly what i do not want.
I want click event only raise when i click on the checkbox and not when the state is changed.
Any idea how to do it ?
Thank you
Upvotes: 3
Views: 1909
Reputation: 16368
Put your Click
event code in the MouseDown
event instead. You'll have to manually set the checkstate though:
Private Sub Check1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Check1.Value = IIf(Check1.Value = vbChecked, vbUnchecked, vbChecked)
' run other necessary code here
End Sub
Upvotes: 2
Reputation: 38895
you can set a flag when you are populating the form from code to ignore changes. This can get messy if the code is not organized well.
Form Level:
Public IgnoreChange As Boolean
Form Load:
IgnoreChange = False
Event:
If IgnoreChange Then Exit Sub
Your code:
frmReference.IgnoreChange = True
frmReference.Checkbox1.Checked = True
frmReference.IgnoreChange = False
Code should only respond to user actions
Upvotes: 4
Reputation: 55029
Not sure if it's the best way, but one way would be to have a variable called something like IgnoreEvents and set that to true right before changed the state programmatically. Then in the event handler if that variable is true, you just exit the event handler without doing anything.
Upvotes: 3