VB.NET - Combo box can't set default

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:

Sub GetEmpID()

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"

End Sub

'On text change from another location:

Sub AutoFillEmpID()

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
    Exit Sub
End if
End Sub

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try setting the SelectedValue instead of text.
Éric MoreauSenior .Net ConsultantCommented:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
holemaniaAuthor Commented:
Thanks, but still not working.  Just strange that for some department code it would select the right ID, and for some it doesn't do it unless I set the combobox to dropdown instead of dropdownlist.  For example, Eng would select the right ID, but Acct doesn't.  I can't see any difference between the 2 other than if i select the property of the combobox to dropdown, then it works fine.  However, I don't want a dropdown combobox since user can type in the ID in there and then I would have to do another validation to see if the ID is an actual ID and in the right department.
holemaniaAuthor Commented:
Thanks for the feedback guys.  Decided to take it the other way and just validate to make sure that the ID is correct.
holemaniaAuthor Commented:
Thanks for the suggestions and help.  Decided to do it differently and set the property to dropdown.  From there, I setup another routine to do a validation before saving/updating.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.