Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

combo box getting a PK from a selected item

Status
Not open for further replies.

steve1rm

Programmer
Aug 26, 2006
255
GB
Hello

I have a combo box with a list of clients. I need to do search on the the PK to get the details of the client. This worked fine, however the customer wants the combo box to be in sorted order. So i set the property for the combo box to sorted. Now that I have done that the client names are in order but do not corrspond to the value member. In the database the clientID is indentity incremented integer.

Code:
Me.cboClients.DataSource = ds1.Tables(0).DefaultView

Me.cboClients.DisplayMember = "Name"
Me.cboClients.ValueMember = "ClientID"

in the selectionchangedcommitted event i have this
Code:
client = Me.cboClients.SelectedValue()
'calls procedures to search for client's details


Is there an easy way to get a PK value form a client that is selected from the combo box. I can't search for the client name, as some clients have the same name. Not unique.

Many thanks in advance,

Steve
 
Any chance you can post the code for your combo-box as well?

I'm not sure why ClientID wouldn't correspond to Name if you're binding it with .DataBind()
 
Problem solved.

in the query just sort them before you put them in the combo box

SELECT * FROM CLIENTS
ORDER BY Name ASC

Simple as that.

Steve
 
Just a note, using a wild card for your queries can slow it down.
djj

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top