I think you're on the wrong track. You can hide or show the checkbox simply by setting its Visible property - no need to try and hide it behind something else, or show/hide the parent container.
From the sound of it, the event procedure which should be causing this to happen is the click event of the first checkbox.
Also, note that checkboxes have not two but
three possible states. In VB6, which I'm familiar with, the possible values are:
- 0 - Unchecked
- 1 - Checked
- 2 - Grayed
Presumably there are equivalent constants in VB.Net. Note that there are some implications of this - for example, a Boolean really isn't appropriate to store the information, since it can only represent two different states.
I'd also like to mention a couple of other points...
- The .Enabled property doesn't affect the contents - just whether the user can interact with it.
- This is a lot of unnecessary coding...
- If x = False Then
-
CheckBox2.Enabled = False
-
Else
-
CheckBox2.Enabled = True
-
End If
You don't have to use boolean (True/False) values by testing them with something like an IF statement. You can simply transfer them directly like any other value. For example, the above snippet of code could be written in a single line