I'm running into an issue where on initial load of my windows form, I would populate a combobox. Base on selection, I want that combo box to change, but for some reason if it's property is listed as "DropDownList", it won't change.
My first code populate the combobox with IDs on initial form load. If a department is fill in, it'll automatically select the right ID. It's not doing that if I set it to dropdownlist. If I just set it to dropdown, it works fine. Any reason why?
'On form load:
strQuery = "Select distinct ID from Employee"
Dim con String = "data source=SVR1;persist security info=False;initial catalog=db1;UID=sa;PWD=Password1"
Dim da as New SqlClient.SqlDataAdapter(strQuery, con)
Dim ds as Dataset = New Dataset
cboEmpID.Datasource = ds.Tables(0)
cboEmpID.DisplayMember = ds.Tables(0).Columns("ID").ColumnName.ToString
cboEmpID.ValueMember = "ID"
'On text change from another location:
Dim strConnect as String = "data source=SVR1;persist security info=False;initial catalog=db1;UID=sa;PWD=Password1"
Dim strEmpQuery as String = ("Select distinct ID from employee where Dept = '" & txtDept.text & "' ")
Dim con as New sqlclient.sqlconnection(strConnect)
Dim cmd as New sqlclient.sqlcommand(strEmpQuery, con)
drEmployee = con.ExecuteReader(CommandBehavior.CloseConnection)
If drEmployee.HasRows Then
cboEmpID.Text = drEmployee.Item("ID").ToString