How to make a textbox visible after selecting text in combobox

rwensley
rwensley used Ask the Experts™
on
This should be simple enough but I a m having trouble figuring it out.

I have two controls on a page a combobox and a text box. I want the text box to appear if I select the an option in the combobox. The combobox has two items in its' collection properties Yes and No. If I select Yes I want the text box to appear. What is the easiest way to do this? Here is the code i have so far. Thank you for your help in advance.
Public Class Form3

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.ValueMember = "Yes" Then
            TextBox1.Visible = True
        End If
    End Sub
End Class

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
add this code to the click event of combobox1

TextBox1.Visible = ComboBox1.Value

Author

Commented:
Error      1      'Value' is not a member of 'System.Windows.Forms.ComboBox'.      

Commented:
so you are using vb.net
instead of value use checked
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

Author

Commented:
'Checked' is not a property of a ComboBox either.

Commented:

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.SelectedItem = "Yes" Then
            TextBox1.Visible = True
        Else
            TextBox1.Visible = False
        End If
    End Sub

Open in new window

It would matter what you have for the item in the combobox. you might need to ComboBox1.SelectedItem.ToString() = "YES" make sure that if in the combo box you have all capital letters you have it here to.

one more way is to just use ComboBox1.text = "Yes" the text will change when the user selects different items
Most Valuable Expert 2012
Top Expert 2014

Commented:
Why not use the Text property of the combobox?

If cbx.Text = "Yes" Then
   txt.Visible = True
Else
   txt.Visible = False
End If
Commented:
I tested both ComboBox1.SelectedItem and ComboBox1.Text.  They both work.  ToString is not necessary if you know what is in ComboBox1.Items.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial