I've tried myself, but I'm not sure if they are better than the one I posted in my original question. Here they are:
Use the
Find()
method ofBindingSource
://Only 1 line of code, seems to much cleaner :) myComboBox.SelectedIndex = new BindingSource(myComboBox.DataSource,"").Find("ID",3); //In fact, I thought of this before but I had tried the solution in my OP first.
Use a little trick with
FindStringExact()
method ofComboBox
:string currentDisplayMember = myComboBox.DisplayMember; myComboBox.DisplayMember = "ID"; myComboBox.SelectedIndex = myComboBox.FindStringExact("3"); myComboBox.DisplayMember = currentDisplayMember;
The #2 should be used carefully if you have something related to DisplayMember
to handle when the SelectedIndexChanged
is fired.
I hope this helps others. Please leave your comment below if they're better than the method I used in my original question. Thanks!