I have a project in WinForm where I have a ComboBox. What I want to do is copy the value of the SelectedValue
property into a variable of type int
.
private void cbIzq_SelectedIndexChanged(object sender, EventArgs e)
{
lblNombreIzq.Text = cbIzq.Text;
int personaId = Int32.Parse(cbIzq.SelectedValue);
lblEstaturaIzq.Text = GetEstatura(personaId) + " cm";
}
private string GetEstatura(int persona)
{
return ListaMedidas.Where(x => x.persona == persona).Select(e => e.estatura).FirstOrDefault().ToString();
}
But it throws me the error:
cannot convert from 'object' to 'string'
What should I do to solve it?
See how to use Int32.Parse
Fixing it with the code below seems to solve the problem.
int personaId = Int32.Parse(cbIzq.SelectedValue.ToString())