Good Morning. It turns out that I have two textboxes in my Windows Forms application, and I need both textboxes to be filled with text from the same dataGridView.
When I click the query button, a DataGridView opens, with the data from the PERSONAL table identified by name and ID. When I click twice on the same row, the id of the person I have selected should be put in the From Operator textBox and I want that when I hit the second Query button (the Until Operator) the same DataGridView opens and selects another operator and it is placed in the Until Operator TextBox .
Here comes the problem, when he opens the second query button and the same DataGridView appears when I select a name, in the from operator textbox it is the same as the one I select to put in the To Operator textbox . I send the code, in case you can help me. Thanks in advance.
private void eCellDoubleClick(object sender, DataGridViewCellEventArgs e)
{
// Si el doble click se ha hecho en alguna celda de la cabecera no hacer nada
if (e.RowIndex == -1)
{
return;
}
switch ((sender as Control).Name)
{
//DataGridView
case "dgvPersonal":
Formulario_Consulta f1 = Application.OpenForms.OfType<Formulario_Consulta>().SingleOrDefault(); //Devuelve un solo elemento en la secuencia
if (f1 != null)//o sea el formulario de consulta está abierto y no se ha cerrado
{
int id_persona = (Int32)dgvPersonal.CurrentRow.Cells[ID_PERSONA].Value; //Sacamos el valor de la id persona correspondiente que al hacer doble click, sobre ella.
int id_persona2 = (Int32)dgvPersonal.CurrentRow.Cells[ID_PERSONA].Value; //Sacamos el valor de la id persona correspondiente que al hacer doble click, sobre ella.
f1.tb_Desde_Operario.Text = id_persona.ToString(); //y le añadimos al textbox correspondiente el id de la persona para hacer la pertinente consulta
f1.tb_Hasta_Operario.Text = id_persona2.ToString();
Close(); //Cierro el formulario de consulta del personal.
}
break;
default:
//...
break;
}
}
You have a program structure problem, since the event is executed every time you double-click the grid, and therefore, it modifies the 2 textboxes with the value of the selected cell.
You can solve your problem with a simple
if
as follows: