[.net] Combo Boxes + Value/ID
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?
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?
One way of doing this
Then use databinding to the SelectedValue from the db. Use the design. It's easier.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement