Sunday, April 3, 2011

combobox in vb.net

how to hide or disable items in one combobox on the basis of selected item in another combobox in vb.net?

From stackoverflow
  • Manipulate the datasource of the second combobox in the selected index changed event of the first one.

  • 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

    Gerrie Schenck : I think he wants the data inside Combobox2 to change.
    Cerebrus : "she" wants... ;-)
    Drahcir : Changed my answer, hope it was you needed
  • 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???

0 comments:

Post a Comment