你这段代码应该能实现了啊,加个条件吧
if (e.RowIndex >-1)
{
string f_id = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); //记录选中行的成员序号
textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
textBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
textBox4.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
textBox5.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
}