mercredi 25 février 2015

WinForms ComboBox

I'm trying to mark one of the combobox items as selected.


So I am building my combobox like this:



var drop = new Dictionary<int, string>();
while (RegReader.Read())
{
drop.Add(Convert.ToInt32(RegReader["intRulesID"]), RegReader["txtName"].ToString());
}

RegRuleDrop.DataSource = new BindingSource(drop, null);
RegRuleDrop.DisplayMember = "Value";
RegRuleDrop.ValueMember = "Key";


Now, one of the items within the RegRuleDrop should be pre selected based on a value from a reader above this code. Now, the problem is that I need to select value based on the actual ListItem VALUE and not TEXT.


So as an example



drop.Add(1, "Test");
drop.Add(2, "Test2");
drop.Add(3, "Test3");


I need to find the index using 1,2 or 3 not Test, Test2 or Test3


Any ideas?


Aucun commentaire:

Enregistrer un commentaire