how to hide or disable items in one combobox on the basis of selected item in another combobox in vb.net?
+2
A:
Manipulate the datasource of the second combobox in the selected index changed event of the first one.
Gerrie Schenck
2009-02-25 08:05:13
+2
A:
As gerrie said , you have to make a condition in the second combobox selected indexed changed event, like so :
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedValue = "my Value" Then
ComboBox2.Visible = False
End If
End Sub
Where "my value" is a value I have in combobox1
Edit :
The combobox keeps the values inserted unless you clear them. By using this line of code
ComboBox2.Items.Clear()
Or otherwise you put the values in a list like a Datatable and point the combobox datasource of that specific Datatable
Drahcir
2009-02-25 08:14:40
I think he wants the data inside Combobox2 to change.
Gerrie Schenck
2009-02-25 08:23:21
"she" wants... ;-)
Cerebrus
2009-02-25 08:53:03
i think u r nt getting my problem. situation is like this..combobox1 combobox2red appleblue mangogreen grapesyellow orangewhen i select a value from combobox2 only 2 values must be visible from box1,rest are not..how to do this..
2009-02-25 09:46:12
Changed my answer, hope it was you needed
Drahcir
2009-02-25 10:11:17
thanks..my problem has been solved..i hv used the remove() method before adding any other item in each if case..
2009-02-25 10:38:49
A:
i hv tried this.
combobox2_selectedindexchange()
if combobox2.selectedindex=0 then
combobox1.items.add("apple")
combobox1.items.add("mango")
elseif combobox2.selectedindex=1 then
combobox1.items.add("grapes")
combobox1.items.add("banana")
end if
it is adding the items on change of index.. but it is also displaying previously added items also.. wat to do???