To be able to assign the fields from DataGridView
to TextBox
you have to do it in the following way:
Creating a function that fills the TextBox
public static void LlenarTextBox(int IndiceDGV)
{
TextBox1.Text = DataGridView1.Rows[IndiceDGV].Cells[0].Value.ToString(); //TextBox1 = Ap.Paterno
TextBox2.Text = DataGridView1.Rows[IndiceDGV].Cells[1].Value.ToString(); //TextBox2 = Ap.Materno
TextBox3.Text = DataGridView1.Rows[IndiceDGV].Cells[2].Value.ToString(); //TextBox3 = Nombre
}
IndiceDGV
would be the current index of the row you want to select in DataGridView
. Then the function is called in the event Click
of each button in the following way:
private void Button1_Click(object sender, EventArgs e)
{
LlenarTextBox(0);
}
In this case, the zero ( 0
) is sent indicating the first row.
To make the code more homogeneous, you could do the following:
private void Button1_Click(object sender, EventArgs e)
{
LlenarTextBox(DataGridView1.CurrentRow.Index);
}
But I'm not sure if clicking on the button this property is full.