0
I have a program in windows Forms and I need to select the item in a combo box so that the user can edit the record, however, it receives the value, finds the index but does not return the selected on the screen. follows the code:
private void PreencherCbox(List<Natureza> lista)
{
List<CboxModel> model = new List<CboxModel>();
CboxModel p = new CboxModel();
p.Text = "Selecione uma natureza";
p.Value = "0";
model.Add(p);
foreach (Natureza n in lista)
{
CboxModel m = new CboxModel();
m.Text = n.Descricao;
m.Value = n.Id.ToString();
model.Add(m);
}
this.CboxNatureza.DataSource = model;
CboxNatureza.DisplayMember = "Text";
CboxNatureza.ValueMember = "Value";
}
and when to receive the value and select:
this.CboxNatureza.SelectedIndex = CboxNatureza.FindStringExact(e.Natureza.Descricao);
I have another piece of code that is the same, but it works. Help! = D
The correct would not be you refer to the value set for
this.CboxNatureza.SelectedValue
?– Leandro Angelo
I tried too and could not. In my other form I do the same way as shown above and works perfectly...
– Ivo Júnior