Quote:
Originally Posted by Plater
What you are doing seems like it should work with the SelectedValue, not sure why it doesn't.
Are you able to maybe switch to a Dictionary<IDType,Something> collection and set it as your data source (or something like that instead. Then you can reference the Dictionary with the ID and get the item to set to SelectedItem?
I'll look into this...but I'd really prefer not to use a Dictionary.
I'm working on an example application for other developers to reference so that they understand how to use certain functionality. Since I have no idea how much my audience knows about software development I was even reluctant to introduce the very simple private class described above....
I just didn't feel like adding the ID to the string displayed in the combo box...only to have to parse the string later (I find parsing Strings a chore and it can complicate examples)
Quote:
Originally Posted by Plater
When the combobox is just strings, I use the .Items.Contains("string value I want")
When the combobox uses a datasource (mine are always DataTables, sorry), I had to jump through some hoops.
-
//dd is the DataTable that was used as a datasource
-
DataRow[] dd = dt.Select("[Client Company] ='Philips Healthcare'");
-
int rowidx = dt.Rows.IndexOf(dd[0]);
-
cbClientCompany.SelectedItem = dt.DefaultView[rowidx];
-
Interesting.....
Quote:
Originally Posted by Plater
Only thing I could think of is maybe you can use the SelectedIndex proeprty instead?
This wont simplify things because I don't know what index the item's ID exists at....I'd still have to loop through the items in the combo box to find the index.
-Frinny