• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 378
  • Last Modified:

Uncheck checkbox when other checkbox is selected

I have three checkboxes:

prodCheck
tankCheck
dateCheck

I have been trying to write some code that will uncheck the other checkboxes that are NOT selected.  I thought that I could just write something like:

If tankCheck.Checked = True Then
    prodCheck.Checked = False
End If

But, that doesn't work.  In other words, you can only have one checkbox selected at a time.
0
johnqtr
Asked:
johnqtr
1 Solution
 
softplusCommented:
You need to access the Checked properties with the enumerator:
i.e.
if tankCheck.Checked = CheckState.Checked then
  prodCheck.Checked = CheckState.Unchecked
  dateCheck.Checked = CheckState.Unchecked
elseif prodCheck.Checked = CheckState.Checked then
  tankCheck.Checked = CheckState.Unchecked
  dateCheck.Checked = CheckState.Unchecked
elseif dateCheck.Checked = CheckState.Checked then
  prodCheck.Checked = CheckState.Unchecked
  tankCheck.Checked = CheckState.Unchecked
end if

HOWEVER: I wouldn't do this - I'd use option boxes or even a combo dropdown. It's much cleaner and the user will know which action to expect. Checkboxes that automatically uncheck when you select a different option are kind of scary :)

John
0
 
Jeff CertainCommented:
Create a single event handler than handles teh events for all 3 check boxes. Then, use this code:

If prodCheck.Checked OrElse tankCheck.Checked then dateCheck.Checked = False
If tankCheck.Checked OrElse dateCheck.Checked then prodCheck.Checked = False
If prodCheck.Checked OrElse dateCheck.Checked then tankCheck.Checked = False
0
 
YZlatCommented:
use RadioButton instead
0
 
johnqtrAuthor Commented:
Dropdown would be better.  I just didn't think about that.  Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now