Establezca el elemento seleccionado de un cuadro combinado basado en la clave, el par de valores.
Tengo un cuadro combinado que relleno así:
this.reqTypeInput.Items.Add(new RequestType("Label 1", "Value1"));
this.reqTypeInput.Items.Add(new RequestType("Label 2", "value2"));
this.reqTypeInput.Items.Add(new RequestType("Label 3", "value3"));
Mi clase RequestType es:
class RequestType
{
public string Text { get; set; }
public string Value { get; set; }
public RequestType(string text, string val)
{
Text = text;
Value = val;
}
public override string ToString()
{
return Text;
}
}
Tengo un valor, "Valor1", por ejemplo. ¿Cómo puedo configurar el elemento seleccionado del cuadro combinado en el objeto {Etiqueta 1, Valor1}?
Yo he tratado
this.reqTypeInput.SelectedIndex = this.reqTypeInput.Items.IndexOf("Value1");