Combobox - Is this the right way?

  • Thread starter Thread starter Gary Paris
  • Start date Start date
G

Gary Paris

I have a question regarding the combobox. I populated a Combobox on my
Windows form by databinding. In table I am binding contains a StaffID field
and a StaffName field.

When I ran a query to retrieve a field, I wanted to display the correct
value (StaffName) in the combobox. This is the code I came up with to do
that and was wondering if there is an automatic way to do this without
looping through the combobox


For index = 0 To cmbStaff.Items.Count - 1
cmbStaff.SelectedIndex = index
If rowContact("staff") = cmbStaff.SelectedValue Then
Exit For
End If
Next

Thanks,

Gary
 
Gary,

You documented it almost complete, however is "staff" the staffId or the
staffName and how do you get the row. Because when you know its position you
have the index. (And is it a datarow or a datarowview (the row from a
dataview)

Cor
 
Thanks for the input. I didn't know you could just set the SelectedValue.
I learned something new today.

Gary
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top