Sign in to follow this  

[.net] Combo Boxes + Value/ID

This topic is 3862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've found out how to display a name which corresponds to an ID for combo boxes. Not as hard as I had thought. My next question is, I am connecting to a database and using the combo box as a method to display a piece of information, which will be different for each DB entry, but for all DB entries they can be one of 5 things. My question is, the value from the DB is the same as the IDs for the combo box. Now if I go combobox1.selected=ODBCDR[1] for example, would that not try to find the name which matches, instead of the ID. So to clarify, my combobox would be set up like this for example: Name ID Monday Mon Tuesday Tue Wednesday Wed Thursday Thurs Friday Fri Saturday Sat Sunday Sun Now the DB value would be say Thurs...If I do the combobox1.selected=OdbcDR[1] would it make Thursday selected, or give me an error?

Share this post


Link to post
Share on other sites
Ok, so I don't have the displaymember and valuemember properties figured out. I have 2 different arrays, one for the names and the other for the values. The values in each array are related but change on a whole depending on which underlying factor is chosen. I'm having trouble making it so that the combo box will display one array as its values and use the other as the names of each value. How can I work around this?

Share this post


Link to post
Share on other sites
One way of doing this


DataTable days = new DataTable();
days.Columns.Add("value");
days.Columns.Add("display");
days.Rows.Add("Mon", "Monday");
days.Rows.Add("Tue", "Tuesday");
...
combobox.ValueMember = "value";
combobox.DisplayMember = "display";
combobox.DataSource = days;




Then use databinding to the SelectedValue from the db. Use the design. It's easier.

Share this post


Link to post
Share on other sites

This topic is 3862 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this