Comment puis-je sélectionner l'élément dans la zone de liste déroulante avec la touche "02"?Sélectionner une valeur dans une zone de liste déroulante chargée avec des objets
public class GenericComboBox
{
private string _key = string.Empty;
private string _value = string.Empty;
public string Key
{
get { return _key; }
set { _key = value; }
}
public string Value
{
get { return _value; }
set { _value = value; }
}
public GenericComboBox(string key, string value)
{
_key = key;
_value = value;
}
}
//Add data
IList<GenericComboBox> data = new List<GenericComboBox>();
data.Add(new GenericComboBox("01", "01 text"));
data.Add(new GenericComboBox("02", "02 text"));
data.Add(new GenericComboBox("03", "03 text"));
comboBox1.DataSource = data;
comboBox1.ValueMember = "Value";
//comboBox1.SelectItem With key equal "02"
Merci.
Comment puis-je faire en cas de ne pas avoir accès à des données variables ?. Par exemple si je sélectionne la comboBox dans un événement de clic sur un bouton –
comboBox1.SelectedItem = ((Liste) comboBox1.DataSource) .Find (délégué (GenericComboBox gc) {return gc.Key == "02";}) ; –