Hello.
I asked a question days ago about capturing the value of a cell from a gridview
to a Form
leg% and sending it to a combobox
in the Form
primary. I received a satisfactory response and that causes the Form
primary to receive the value, however when I try to change the index from combobox
to the index I received the error message Value of 'X' is not valid for ' SelectedIndex ', where X is the received value.
It is worth mentioning that when starting the application this same combobox
cbComputer is filled with data from a DB table, according to code. I would like to know if there is any way to resolve this impasse.
% Fill_code%:
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 load combobox
with the above method values:
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 answer.
If it was not clear enough, please comment that I try to explain it again in more detail.
Thank you for your attention.