Reputation: 2273
I have a little problem that i'm creating a simple search application which have a TEXT box and some combo boxes and radio buttons and a search button. radio button names "Videos", "Audios", "Pics" etc.. when radiobutton of video is selected, a combobox is appear having options "YouTube", "Metacafe" etc I want that when i click "Metecafe" item in combobox of video, an other combo box appear having items Like "Entertainment", "How To", "+18" etc(categories of video search). so "HOW TO SHOW/HIDE AN OTHER COBOBOX WITH THE HELP OF A COMBOBOX ITEM" hope you have understood my problem. screen shoot i don't know it is possible or not becux i'm beginner in VB my English is not so good so please see below code:)
if combobox1.SelectedItem = "PAKISTAN" Then
combobox2.Visible = True
End if
if combobox1.SelectedItem = "INDIA" Then
combobox3.visible = true
combobox2.visible = false
End if
Obviously this code is wrong, this is a example that what i want to do Thanks to all in advance..
NOTE: i have try this codes but its not working..
if ComboBox1.Items(ComboBox1.SelectedIndex).ToString() = "PAKISTAN" Then
ComboBox2.Visible = True
End if
sorry for spell and grammatical mistakes:(
Upvotes: 2
Views: 7686
Reputation: 54532
Try using the SelectedItem Property like this
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedItem.ToString = "PAKISTAN" Then
ComboBox2.Visible = True
End If
End Sub
Since you are wanting to check for multiple country's you can use a Select Case Statement like this
Private Sub ComboBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Select Case ComboBox1.SelectedItem.ToString
Case "PAKISTAN"
ComboBox2.Visible = True
ComboBox3.Visible = False
Case "INDIA"
ComboBox3.Visible = True
ComboBox2.Visible = False
Case Else
ComboBox2.Visible = False
ComboBox3.Visible = False
End Select
End Sub
Upvotes: 3
Reputation: 108
Two things are important here:
(a) Which event you're using to /detect/ that the combobox has changed, and
(b) The code you're using to detect what is selected.
I haven't tested this, and I'm coming from a C# / VB6 background, so bear with me if this isn't 100% correct, but I believe using the following should work:
Inside the SelectedIndexChanged event of ComboBox1, insert your code above, EXCEPT.. Change instances like
combobox1.SelectedItem = "PAKISTAN"
to
ComboBox1.Text = "PAKISTAN"
The SelectedItem property outputs the selected item object itself, which is a variable type that can't be displayed.. not the /text/ of the currently selected item. There are other ways to access the text associated to that item, but ComboBox1.Text is the easiest. ComboBox1.SelectedItem.ToString() would work also.
Upvotes: 1
Reputation: 1
Btw is this a web client or window client?
Assuming if you are implementing a web client app and the conditional logic are simple, you may need to trigger a page reload which can be achieve in your markup by specifying an event and set the property for reload to enable. My initial on this from reading your post is that your GUI might not be refreshing or reloading unless it's your intension to not reload the page or refresh the GUI then this should be handle with javascript instead.
I hope I'm interpreting the issue correctly and hopefully this will give you some idea on how to tackle the issue.
Upvotes: 0
Reputation: 9193
If ComboBox1.Items(ComboBox1.SelectedIndex).ToString() = "PAKISTAN" Then
ComboBox2.Visible = True
End If
Upvotes: 0