Hi, I'm trying to create cascading comboboxes, and my code isn't working. I've looked at other threads and I don't know why it isn't working properly. The first combo box displays System Names and the second combobox should populate the all Locations of that specific system chosen. When I run my application, the first combobox populates without any duplicates just as it shoud but when I select a System Name from it, the location combo box populates just one entry and doesn't allow a drop down of all the other location names. Here's my code:
'---Form_Load
Dim con As MySqlConnection = New MySqlConnection("Server=fafsv-mysql;user id=root;Password=0263;Database=gsais")
Dim cmd As MySqlCommand = New MySqlCommand("SELECT DISTINCT SystemName FROM blsys_systems", con)
con.Open()
Dim myDA As MySqlDataAdapter = New MySqlDataAdapter(cmd)
Dim myDataSet As DataSet = New DataSet()
myDA.Fill(myDataSet, "blsys_systems")
SystemComboBox.DataSource = myDataSet.Tables("blsys_systems")
SystemComboBox.ValueMember = "SystemName"
SystemComboBox.DisplayMember = "SystemName"
Me.SystemComboBox.SelectedValue = 0
con.Close()
con = Nothing
That part of the code seems to be ok.. here's for the second combo box:
Private Sub SystemComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SystemComboBox.SelectedIndexChanged
'Populates Location Name Combo box cascading from System Name
Dim con As MySqlConnection = New MySqlConnection("Server=fafsv-mysql;user id=root;Password=0263;Database=gsais")
Dim cmd As MySqlCommand = New MySqlCommand("SELECT LocationName, SystemName FROM blsys_systems WHERE SystemName='" & SystemComboBox.Text.ToString & "'", con)
con.Open()
Dim myDA As MySqlDataAdapter = New MySqlDataAdapter(cmd)
Dim ds As DataSet = New DataSet()
myDA.Fill(ds, "blsys_systems")
LocationComboBox.DataSource = ds.Tables("blsys_systems")
LocationComboBox.ValueMember = "LocationName"
LocationComboBox.DisplayMember = "LocationName"
LocationComboBox.SelectedValue = 0
con.Close()
con = Nothing
End Sub
Once I get that to start working, the selection of the second combobox should populate textboxes and different datagrids... :(