1
Hello, my friends!
I am programming in C# and use Visual Studio 2019 to create an application in Forms. I have a combobox that I linked to a table using the Datasource property. When the user selects a value, I need two variables to receive Displaymember and Valuemember values. The routine I did is as follows:
private void Cb_Campo_SelectionChangeCommitted(object sender, EventArgs e)
{
if (_Modo != 0)
{
Cb_Campo.DisplayMember = CampoTexto;
Cb_Campo.ValueMember = CampoChave;
ValorChave = int.Parse(Cb_Campo.SelectedValue.ToString());
ValorTexto = Cb_Campo.SelectedItem.ToString();
}
}
By default, before the selection, the field displays the "Select" text. With the above code, when the user selects a value from the list, the variable Key Value receives the correct value, but the variable Text Value receives the value "System.Data.Datarowview". When I change the line above by...
ValorTexto = Cb_Campo.Text;
...this variable receives the value "Select", as if nothing had been selected.
Can anyone tell me what I’m doing wrong? Thank you.
Talles. I can’t do that, because the datasource already comes from a BD table. But the suggestion is interesting.
– Ismael
– Talles Santana
Hello, Talles. What I did was based on Ricardo’s suggestion (below). Veja como ficou o trecho: 
 Cb_Campo.DisplayMember = CampoTexto;
 Cb_Campo.ValueMember = CampoChave;
 ValorChave = int.Parse(Cb_Campo.SelectedValue.ToString());
 DataRowView dataRowView = (DataRowView)Cb_Campo.SelectedItem;
 ValorTexto = dataRowView.Row[CampoTexto]. Tostring();
– Ismael