Good day of your support with this topic, I am creating a Windows Forms in which I have a ComboBox I load from a table in SQL this table only has 2 records so far and I want to get the ID of the item selected to then store it in another table, I hope you can help me, since I do not remember how to do it.
public void CargaComboClientes()
{
try
{
dtClientes = objConsultas.MuestraClientes();
if (dtClientes.Rows.Count!=0)
{
cmbClientes.DataSource = dtClientes;
cmbClientes.ValueMember = "Cte_ID";
cmbClientes.DisplayMember = "Cte_RazonSocial";
}
}
catch (Exception ex)
{
ex.ToString();
}
}
private void cmbClientes_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
int cteId = 0;
if (cmbClientes.SelectedValue!=null)
{
cteId = Convert.ToInt32(cmbClientes.SelectedValue);
}
}
catch (Exception ex)
{
ex.ToString();
}
}
And doing it this way and wanting to get the value and save it in a variable shows me this exception.
No se puede convertir un objeto de tipo 'System.Data.DataRowView' al tipo 'System.IConvertible'.