הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Wednesday, July 12, 2006 6:30 PM
I am using software that scripts with VB .NET and I am trying to have a textbox hidden unless a combo box above it has "other" selected. So the user will select something from the combo box and if it is "other" then I want a certain textbox to become visible to type information into. If they pick something other than "other" then I want the textbox to remain hidden. Thanks!
All replies (9)
Wednesday, July 12, 2006 6:34 PM ✅Answered
Well when the selectedindex has been changed, you can then check to see the value of the item chosen, and if it matches your condition then make the textbox visible:
if me.theComboBox.SelectedItem.ToString().Equals("other") then
me.theTextBox.Visible = true
else
me.theTextBox.Visible = false
end if
On the combo box, you may implement the SelectedIndexChange event and when you change the value item chosen from the combo box, this event gets fired and from here, you can then make the textbox appear/disappear depending on the condition of your choice.
hope it helps!
Wednesday, July 12, 2006 8:26 PM ✅Answered
change SelectedText to SelectedItem.ToString() then....
on the form, select the textbox and make the visible property to false. this will not show the textbox at all.
in your code, the textbox will become visible when you select an item from the combobox on the selectedindexchange event.
example:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If Me.ComboBox1.SelectedItem.ToString().Equals("other") Then Me.TextBox1.Visible = True Me.TextBox1.Text = "hi" Else Me.TextBox1.Visible = False End If End Sub |
Wednesday, July 12, 2006 7:06 PM
sorry but i have never really used VB before so where would i put that code. Do I put it in a form load or what? I appreciate your help.
Wednesday, July 12, 2006 7:31 PM
Well, you would put the code on the selectedindexchanged event.
so, in your Design View, click on the combobox, then in the properties, select the events button (the one that looks like a lightning symbol)
somewhere in there, there will be a property called something like "selectedindexchanged" - just doubleclick on it to make an event.
once done, you should be automatically be taken into the code and the event should have been created.
here is where you enter that code.
Wednesday, July 12, 2006 8:05 PM
I did what you said and when I open the form it displays both the combo box and text box and then when i select any text from the combo box the text box will disappear. any suggestions??
Wednesday, July 12, 2006 8:09 PM
this is because of the code. if the text selected from the combo box is NOT "other" then it will hide the textbox, otherwise if the text "other" is selected in the combo box, the textbox will appear.
the code given was an example, you will have to modify it to your needs
Wednesday, July 12, 2006 8:11 PM
it goes away no matter what I select. I want the textbox to not be visible when i enter the form and the only way it will become visible is if i select "other" from the combo box. thanks!
Thursday, January 22, 2009 5:20 PM
Thanks for the help But how do you make the textbox once it becomes visible how can you make the rest of the form move down to make way for the now visible textbox (and label in my case) Nadir Hanid
Thursday, January 22, 2009 5:28 PM
I would either just make room for the text box from the get-go, or as an alternate solution, you could disable the textbox until the combobox is changed:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged |
If Me.ComboBox1.text = "Other" |
Me.TextBox1.Enabled = True |
Else |
Me.TextBox1.Enabled = False |
End If |
End Sub |