Reputation: 412
Combobox2 values need to be changed when combobox1 changes value
Private Sub ComboBoxPodelba_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBoxPodelba.SelectedIndexChanged
Dim myconnect As New SqlConnection
myconnect.ConnectionString = Common.connectionString
Dim mycommand2 As SqlCommand = New SqlCommand()
mycommand2.Connection = myconnect
Try
myconnect.Open()
mycommand2.CommandText = "select PodPodelbaIme from PodPodelba where PodelbaFK = '" + ComboBoxPodelba.SelectedValue.ToString + "'"
Dim reader2 As SqlDataReader
reader2 = mycommand2.ExecuteReader()
Dim dt2 As DataTable = New DataTable
dt2.Load(reader2)
ComboBoxPOdPodelba.ValueMember = "PodPodelbaIme"
ComboBoxPOdPodelba.DisplayMember = "PodPodelbaIme"
ComboBoxPOdPodelba.DataSource = dt2
Catch ex As Exception
End Try
End Sub
Upvotes: 1
Views: 654
Reputation: 2563
Try...
Private Sub Combo1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Combo1.SelectedIndexChanged
Dim myconnect As New SqlConnection
myconnect.ConnectionString = Common.connectionString
Dim mycommand2 As SqlCommand = New SqlCommand()
mycommand2.Connection = myconnect
Try
myconnect.Open()
mycommand2.CommandText = "select PodPodelbaIme from PodPodelba where PodelbaFK = '" + Sender.SelectedValue.ToString + "'"
Dim reader2 As SqlDataReader
reader2 = mycommand2.ExecuteReader()
Dim dt2 As DataTable = New DataTable
dt2.Load(reader2)
Combo2.ValueMember = "PodPodelbaIme"
Combo2.DisplayMember = "PodPodelbaIme"
Combo2.DataSource = dt2
Catch ex As Exception
End Try
End Sub
Upvotes: 0