Bound ComboBox grabbing wrong value

My ComboBox isn't storing the right value to the database.  I'd like to show the user the item description but store the item's code to the database

I have the DisplayMember set to the item description and the ValueMember set to the item's code, but it stores what I have in DisplayMember instead of what I have in ValueMember.  Whichever field is showing in the ComboBox is what is saved to the database.

I've tried switching them around, but it always saves to the database whatever is shown.

I've tried doing it in code instead of by setting the properties and the same thing happens.

Can there be something else that I have set wrong that would cause this?
AmyAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
CodeCruiserConnect With a Mentor Commented:
>This is what gets saved to the other table.
For it to be save, a property has to be bound to another binding source etc. Make sure this property is SelectedValue not Text.
0
 
scottlafoyCommented:
it would help trouble shoot if we could see the code in question
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
AmyAuthor Commented:
Scott - There isn't really code for this.  It's done with properties of the ComboBox.
0
 
AmyAuthor Commented:
Lucky - In the article you pointed out, the author makes a query with the ComboBox's property SelectedValue, whereas I've bound my data.  
0
 
Anil GolamariCommented:
let us assume that your dropdown list  id is dd1.

Now you want to assign the selected value to some x.

then you can  work

x = dd1.text;

Can you try this and see what it is storing for you.
0
 
AmyAuthor Commented:
Lucky - I'm not sure I understand you.  Do you mean, if the user types "x" into the ComboBox, what is stored to the database?  I just now did that and I verified that it does store the "x."
0
 
CodeCruiserCommented:
Which property of the combobox did you bind to the database? SelectedValue?
0
 
AmyAuthor Commented:
CodeCruiser -
The DataSource is the BindingSource that the ComboBox made.
The DisplayMember is the item description.
The ValueMember is the item code.
0
 
CodeCruiserCommented:
And which property is bound to the datasource which saves it to DB (the one which saves wrong value).
0
 
AmyAuthor Commented:
DisplayMember is set to the item description.  This is what gets saved to the other table.
0
 
AmyAuthor Commented:
Both SelectedValue and Text are set to "(none)".  Does one of them need to be set to something?

I just now tried setting SelectedValue to the item code, but the item description is still what's saved to the database.
0
 
AmyAuthor Commented:
That was it.  My error wasn't in the property settings.  It was in the code.  

In the following line of code, I changed .Text to .SelectedValue
objSQL.Parameters.AddWithValue("@csr", cboCSR.SelectedValue)


Thank you!
0
 
CodeCruiserCommented:
Glad to help :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.