How To Show Hidden Text Boxes When Items Are Selected In A Combo Box
I have a combo box with 5 different options, 'one player', 'two players', 'three players' etc. My requirement is when user select something from combo box their equivalent text box
Solution 1:
PrivateSub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Text.Trim.Contains("Player 1") = TrueThen
TextBox1.Visible = True
TextBox2.Visible = False
TextBox3.Visible = FalseElseIf ComboBox1.Text.Trim.Contains("Player 2") = TrueThen
TextBox1.Visible = True
TextBox2.Visible = True
TextBox3.Visible = FalseElseIf ComboBox1.Text.Trim.Contains("Player 3") = TrueThen
TextBox1.Visible = True
TextBox2.Visible = True
TextBox3.Visible = TrueEndIfEndSub
Solution 2:
Simply combine the .change() function available in jquery (https://api.jquery.com/change/) with css visibility (visibility:hidden/visible; check http://www.w3schools.com/cssref/pr_class_visibility.asp )
$( "#myComboBox" ).change(function() {
//do what you have to do here
});
Solution 3:
Try something like this:
Sub cbC(sender AsObject, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
SelectCase ComboBox1.SelectedIndex
Case0
TextBox1.Visible = False
TextBox2.Visible = FalseCase1
TextBox1.Visible = True
TextBox2.Visible = FalseCase2
TextBox1.Visible = True
TextBox2.Visible = TrueEndSelectEndSub
Or this, according to what fits better to your needs:
Sub cbC(sender AsObject, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
TextBox1.Visible = (ComboBox1.SelectedIndex = 0)
TextBox1.Visible = (ComboBox1.SelectedIndex = 1)
EndSub
Solution 4:
The TextBox1.Visible = (ComboBox1.SelectedIndex = 0)
works perfectly.
You must also make sure to set Visible under Properties to False for your textboxes and labels. Otherwise you textboxes will initially be visible when you run application.
Post a Comment for "How To Show Hidden Text Boxes When Items Are Selected In A Combo Box"