Hi all!
I have cascading comboboxes and when I choose the value for the first one everything is fine. But when I try to choose the value for the second combo the value of the first disappears. However, the second combobox is populated with the appropriate values and then I have to choose again the value for the first one. This is the code:
For the fisrt Combobox
Dim PostcodeDA As New SqlDataAdapter()
Dim PostcodeTable As New DataTable
PostcodeDA.SelectCommand = New SqlCommand()
PostcodeDA.SelectCommand.Connection = conn
PostcodeDA.SelectCommand.CommandText = "SELECT Postcode,StreetName_LCL, Municipality_LCL FROM T_MUNICIPALITY_STREETS1 WHERE StreetName_LCL= '" & cboStreetName1.Text & "'"
PostcodeDA.Fill(PostcodeTable)
cboPostcode.DataSource = PostcodeTable
cboPostcode.DisplayMember = "Postcode"
cboPostcode.ValueMember = "Municipality_LCL"
cboPostcode.SelectedValue = 0
And for the second (cascading) combobox which is disappeared only when a checked box is checked and thats the reason I wrote it that way:
Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
lblStreetName2.Visible = True
cboStreetName2.Visible = True
lblStreetNumber.Visible = True
txtStreetNumber2.Visible = True
Dim StreetName2DA As New SqlDataAdapter()
Dim StreetName2Table As New DataTable
StreetName2DA.SelectCommand = New SqlCommand()
StreetName2DA.SelectCommand.Connection = conn
StreetName2DA.SelectCommand.CommandText = "SELECT StreetName_LCL FROM T_MUNICIPALITY_STREETS1 WHERE Postcode='" & cboPostcode.Text & "' order by StreetName_LCL"
StreetName2DA.Fill(StreetName2Table)
cboStreetName2.DataSource = StreetName2Table
cboStreetName2.DisplayMember = "StreetName_LCL"
cboStreetName2.ValueMember = "StreetName_LCL"
Me.cboStreetName2.SelectedValue = 0
If CheckBox1.Checked = False Then
lblStreetName2.Visible = False
cboStreetName2.Visible = False
lblStreetNumber.Visible = False
txtStreetNumber2.Visible = False
End If
End Sub