Jump to content
  • Advertisement
Sign in to follow this  
Selacius

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

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!