I have two Combo Boxes on my form. I sucessfully set the datasource for the first ComboBox using the below code :
"Dim strSQL As String = "Select Employer From Employer"
Dim DA As New SqlDataAdapter(strSQL, objConn)
Dim DS As New DataSet
DA.Fill(DS, "Employer")
Dim dt As New DataTable
dt.Columns.Add("Employer", GetType(System.String))
Dim drDSRow As DataRow
Dim drNewRow As DataRow
For Each drDSRow In DS.Tables("Employer").Rows()
drNewRow = dt.NewRow()
drNewRow("Employer") = drDSRow("Employer")
dt.Rows.Add(drNewRow)
Next
UpdateEmployeeCombo1.DropDownStyle = ComboBoxStyle.DropDownList
With UpdateEmployeeCombo1
.DataSource = dt
..DisplayMember = "Employer"
.ValueMember = "Employer"
.SelectedIndex = 0
End With"
--------------------------
This is done when the form is loaded and it works fine. The problem is I would like to set the datasource for my second ComboBox using the value select by in ComboBox1. That is, it displays a list of Employer Numbers and I would like to use the value chosen in the select statement when setting the datasource for the other. Im also unclear as to where to put whatever code I eventually come with. Any suggestions?
"Dim strSQL As String = "Select Employer From Employer"
Dim DA As New SqlDataAdapter(strSQL, objConn)
Dim DS As New DataSet
DA.Fill(DS, "Employer")
Dim dt As New DataTable
dt.Columns.Add("Employer", GetType(System.String))
Dim drDSRow As DataRow
Dim drNewRow As DataRow
For Each drDSRow In DS.Tables("Employer").Rows()
drNewRow = dt.NewRow()
drNewRow("Employer") = drDSRow("Employer")
dt.Rows.Add(drNewRow)
Next
UpdateEmployeeCombo1.DropDownStyle = ComboBoxStyle.DropDownList
With UpdateEmployeeCombo1
.DataSource = dt
..DisplayMember = "Employer"
.ValueMember = "Employer"
.SelectedIndex = 0
End With"
--------------------------
This is done when the form is loaded and it works fine. The problem is I would like to set the datasource for my second ComboBox using the value select by in ComboBox1. That is, it displays a list of Employer Numbers and I would like to use the value chosen in the select statement when setting the datasource for the other. Im also unclear as to where to put whatever code I eventually come with. Any suggestions?