Uncheck checkbox when other checkbox is selected

I have three checkboxes:


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.
Who is Participating?
You need to access the Checked properties with the enumerator:
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 :)

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
use RadioButton instead
johnqtrAuthor Commented:
Dropdown would be better.  I just didn't think about that.  Thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.