By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,967 Members | 2,124 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,967 IT Pros & Developers. It's quick & easy.

Greyed Out Checkbox

P: 8
I need to be able to greyout one checkbox untill another is checked. I've tried using a split containter w/ two panels, and was able to hide the other text box. The trick was that if you checked the first the second would show, and you could check it. However, if you unchecked the first the second would hide but remain checked. If someone could point me in the right direction in regards to the type of method and event style it would be greatly appreciated.

Thanks,
M
Apr 26 '07 #1
Share this Question
Share on Google+
2 Replies


P: 8
A little more clarification. I think I found what I was looking for.

Expand|Select|Wrap|Line Numbers
  1. Private Sub SplitContainer1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles SplitContainer1.MouseEnter
  2.         Dim x As Boolean = CheckBox1.CheckState
  3.         If x = False Then
  4.             CheckBox2.Enabled = False
  5.         Else
  6.             CheckBox2.Enabled = True
  7.         End If
  8.     End Sub
But is it possible to activate this sub by default rather than by some event, as above.

Thanks,
M
Apr 26 '07 #2

Expert 5K+
P: 8,434
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...
    Expand|Select|Wrap|Line Numbers
    1. If x = False Then
    2.   CheckBox2.Enabled = False
    3. Else
    4.   CheckBox2.Enabled = True
    5. 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
    Expand|Select|Wrap|Line Numbers
    1. CheckBox2.Enabled = x
Apr 26 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.