Correct method to get ComboBox value populated by DataTable

1

What is the correct way to get the value of a ComboBox populated by a DataTable ?

I'm using the following code:

private void ComboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
    Consulta_cidade cidade = new Consulta_cidade();

    var dataRowView = this.comboBox3.SelectedItem as DataRowView;
    var valor = dataRowView.Row.ItemArray[1];

    int a = Convert.ToInt32(valor);

    comboBox2.DataSource = cidade.consulta_cidade(a);
    comboBox2.ValueMember = "descricao";
    comboBox2.DisplayMember = "descricao";
    comboBox2.Update();
}
    
asked by anonymous 22.07.2016 / 01:59

1 answer

3

Just do the conversion to integer using the ToInt32() method see:

int valor = Convert.ToInt32(comboBox3.SelectedValue);
    
30.07.2016 / 16:57