0
Hello.
I asked a question days ago about capturing the value of a cell gridview
in a Form
secondary and send it to a combobox
in the Form
primary. I have received a satisfactory response which causes the Form
primary receives the value, however when I try to change the content of the combobox
for the index I received the error message Value of 'X' is not Valid for 'Selectedindex', where X is the value received.
It is worth noting that when starting the application this same combobox
cbComputer is filled with data from a BD table according to code. I wonder if there is any way to resolve this impasse.
Code for completing the combobox
:
public DataTable GetIdentificador()
{
DataTable dataUf = new DataTable();
bdConn = new MySqlConnection("Persist Security Info=False;server=localhost;database=controle;uid=root;pwd=''");
try
{
bdConn.Open();
if (bdConn.State == ConnectionState.Open)
{
//Se estiver aberta faz a consulta dos dados do BD
MySqlCommand cmd = new MySqlCommand("SELECT identificador FROM computador WHERE status=0", bdConn);
dataUf.Load(cmd.ExecuteReader());
cmd.Dispose();
}
bdConn.Close();
bdConn.Dispose();
}
catch (Exception ex)
{
MessageBox.Show("Impossível estabelecer conexão.\n" + ex.Message);
}
return dataUf;
}
When I carry combobox
with the values of the above method:
public void Form1_Load(object sender, EventArgs e)
{
cbComputador.ValueMember = "identificador";
cbComputador.DisplayMember = "identificador";
cbComputador.DataSource = GetUF();
}
Link to the question I asked earlier with the answer here. In this case, I am using the first option given in the reply.
If not clear enough, please comment that I try to explain again in more detail.
Thank you for your attention.
When I use the Selectedvalue it does not change what is being displayed in the combobox
– DLopes
It seems that the value is lost once I insert a
gridview
in the same Form and run the same line with Selectedvalue it works normally.– DLopes