Discussion:
Checkbox needs Double Click to check
(too old to reply)
James
2010-01-18 05:34:26 UTC
Permalink
I'm trying to uncheck checkbox1 when checkbox2 is checked, and uncheck
checkbox2 when checkbox1 is checked.

However, with my code (to uncheck the opposite box) in the Click event of a
check box, Two clicks are required to display the check.
The first click seems to select the checkbox control, then the second click
does it.

Any suggestions appreciated.
Nobody
2010-01-18 06:39:20 UTC
Permalink
Post by James
checkbox1
It seems from the default names that you posted that you are using dotnet.
This group is for VB6 and earlier(VB Classic). VB.Net and all dotnet groups
have either "dotnet" or "vsnet" in the group name. Please use the following
group instead:

news://msnews.microsoft.com/microsoft.public.dotnet.languages.vb
Saga
2010-01-18 15:29:23 UTC
Permalink
Post by James
I'm trying to uncheck checkbox1 when checkbox2 is checked, and uncheck
checkbox2 when checkbox1 is checked.
snipped

And if using VB6...

If I understand correctly, you do not want both checkbox 1 and 2 checked
at the same time - it should be either one or the other. If this is the
case, a
option button is more suited for this application. Saga
James
2010-01-18 16:02:26 UTC
Permalink
Post by Saga
Post by James
I'm trying to uncheck checkbox1 when checkbox2 is checked, and uncheck
checkbox2 when checkbox1 is checked.
snipped
And if using VB6...
If I understand correctly, you do not want both checkbox 1 and 2 checked
at the same time - it should be either one or the other. If this is the
case, a
option button is more suited for this application. Saga
Using VB6
Option buttons are not suited for my app, there is an exception in my app
that will allow both boxes to be checked.

Anyway, my test code below.

Private Sub chkBox2_Click()
chkBox1.Value = vbUnchecked
End Sub

Private Sub chkBox1_Click()
chkBox2.Value = vbUnchecked
End Sub
Larry Serflaten
2010-01-18 16:44:35 UTC
Permalink
Post by James
Post by Saga
Post by James
I'm trying to uncheck checkbox1 when checkbox2 is checked, and uncheck
checkbox2 when checkbox1 is checked.
snipped
Using VB6
Option buttons are not suited for my app, there is an exception in my app
that will allow both boxes to be checked.
Try the code below. For the exception case, use: SetCheck 3

LFS


Private Sub Check1_Click()
If Check1.Value = vbChecked Then SetCheck 1
End Sub

Private Sub Check2_Click()
If Check2.Value = vbChecked Then SetCheck 2
End Sub

Sub SetCheck(Value As Long)
Static Busy As Boolean
If Busy Then Exit Sub
Busy = True
Check1.Value = vbChecked And ((Value = 1) Or (Value = 3))
Check2.Value = vbChecked And (Value > 1)
Busy = False
End Sub
James
2010-01-19 23:37:01 UTC
Permalink
Post by Larry Serflaten
Post by James
Post by Saga
Post by James
I'm trying to uncheck checkbox1 when checkbox2 is checked, and uncheck
checkbox2 when checkbox1 is checked.
snipped
Using VB6
Option buttons are not suited for my app, there is an exception in my app
that will allow both boxes to be checked.
Try the code below. For the exception case, use: SetCheck 3
LFS
Private Sub Check1_Click()
If Check1.Value = vbChecked Then SetCheck 1
End Sub
Private Sub Check2_Click()
If Check2.Value = vbChecked Then SetCheck 2
End Sub
Sub SetCheck(Value As Long)
Static Busy As Boolean
If Busy Then Exit Sub
Busy = True
Check1.Value = vbChecked And ((Value = 1) Or (Value = 3))
Check2.Value = vbChecked And (Value > 1)
Busy = False
End Sub
Thanks Larry
That solved it.
Thanks for your time.

Jon Lewis
2010-01-18 16:52:19 UTC
Permalink
Post by James
Post by Saga
Post by James
I'm trying to uncheck checkbox1 when checkbox2 is checked, and uncheck
checkbox2 when checkbox1 is checked.
snipped
And if using VB6...
If I understand correctly, you do not want both checkbox 1 and 2 checked
at the same time - it should be either one or the other. If this is the
case, a
option button is more suited for this application. Saga
Using VB6
Option buttons are not suited for my app, there is an exception in my app
that will allow both boxes to be checked.
Anyway, my test code below.
Private Sub chkBox2_Click()
chkBox1.Value = vbUnchecked
End Sub
Private Sub chkBox1_Click()
chkBox2.Value = vbUnchecked
End Sub
Try the same code in the MouseUp events. (This logic will let you have both
unchecked but NOT both checked btw).
(Mr Nobody seems to be suffering from .n3t paranoia!)

HTH
Nobody
2010-01-18 17:58:28 UTC
Permalink
Post by Jon Lewis
(Mr Nobody seems to be suffering from .n3t paranoia!)
Nope. VB.Net uses Checkbox1 for a default name, while VB6 uses Check1. Many
posters end up posting here by mistake, and the OP seems to be new here.
Jeff Johnson
2010-01-18 18:54:35 UTC
Permalink
Post by James
Anyway, my test code below.
Private Sub chkBox2_Click()
chkBox1.Value = vbUnchecked
End Sub
Private Sub chkBox1_Click()
chkBox2.Value = vbUnchecked
End Sub
Yep, I knew that was going to be the case. Do you understand what's
happening? Setting the Value property of a check box RAISES a Click event
(but apparently only if the value is changing), so you've got a (brief)
ping-pong effect happening.
Continue reading on narkive:
Loading...