# [.net] Combo Boxes + Value/ID

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

## 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 on other sites
You would use the SelectedValue property, but yes, you could do this.

##### 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 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.

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 13
• 10
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632998
• Total Posts
3009808
• ### Who's Online (See full list)

There are no registered users currently online

×