DataGridView selected row to display in text boxes

Select cellclick event of datagridview

Add code in cellclick event

if (e.RowIndex >= 0)
{
    //gets a collection that contains all the rows
    DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
    //populate the textbox from specific value of the coordinates of column and row.
    txtid.Text = row.Cells[0].Value.ToString();
    txtfname.Text = row.Cells[1].Value.ToString();
    txtlname.Text = row.Cells[2].Value.ToString();
    txtcourse.Text = row.Cells[3].Value.ToString();
    txtgender.Text = row.Cells[4].Value.ToString();
    txtaddress.Text = row.Cells[5].Value.ToString();
}

For More information use this link How to Display Selected Row from Datagridview into Textbox using C#


You can use SelectedRows property.

Example:

if(dataGridView1.SelectedRows.Count > 0) // make sure user select at least 1 row 
{
   string jobId = dataGridView1.SelectedRows[0].Cells[0].Value + string.Empty;
   string userId = dataGridView1.SelectedRows[0].Cells[2].Value + string.Empty;

   txtJobId.Text = jobId;
   txtUserId.Text = userId;
}