This discussion assumes you have your combobox bound to a dataview. If you are using a datatable, then you can use the DefaultDataView member of the datatable as the DataSource for your combobox.
In this DataView case, the combobox's Items member is a collection of DataRowViews. We can use these DataRowViews to get the corresponding DisplayMember if we know the ValueMember, and vice versa.
The next comment is that the FindString and FindStringExact work only with the DisplayMember. So, they will not help you in looking for a ValueMember. Our solution is to add a public method to a derived combobox that does a 'FindStringExact' except that it looks at the ValueMember of the DataRowView instead of the DisplayMember. Below are some code snippets.
Clay
public class MyComboBox : ComboBox
{
public int FindExactValueMember(object find)
{
return FindExactValueMember(find, 0);
}
public int FindExactValueMember(object find, int start)
{
for (int i = start; i < this.Items.Count; ++i)
{
DataRowView drv = this.Items[i] as DataRowView;
if(drv != null && find.Equals(drv[this.ValueMember]))
return i;
}
return -1;
}
}
//....
//usage
int index = comboBox1.FindExactValueMember(56);
if(index > -1) comboBox1.SelectedIndex = index;