[英]Link Two Comboboxes vb net
當combobox1改變值時,需要更改Combobox2值
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
嘗試...
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.