The CellContentClick works for subsequent selections, but does not fill the text boxes for when the datagridview is first displayed. However, you can use a separate method to fill the textboxes, passing in the e.RowIndex. After the datagridview has been displayed, call the method with the row value of the initial 'record'.
<br />
<br />
dgvExceptions.DataSource = ds.Tables[0];<br />
2. dgvExceptions.Columns[0].HeaderText = "ID";<br />
3. dgvExceptions.Columns[0].Width = 30;<br />
4. dgvExceptions.Columns[0].DefaultCellStyle.Alignment =<br />
5. DataGridViewContentAlignment.MiddleRight;<br />
6. dgvExceptions.Columns[1].Visible = false;<br />
7. dgvExceptions.Columns[2].HeaderText = "Occurred On";<br />
8. dgvExceptions.Columns[2].Width = 70;<br />
9. dgvExceptions.Sort(dgvExceptions.Columns[2], ListSortDirection.Descending);<br />
10. dgvExceptions.Columns[3].Visible = false;<br />
11. dgvExceptions.Columns[4].Visible = false;<br />
12. dgvExceptions.Columns[5].Visible = false;<br />
13. dgvExceptions.Columns[6].Visible = false;<br />
14. dgvExceptions.Columns[7].Width = 317;<br />
15. dgvExceptions.Columns[8].Visible = false;<br />
16. dgvExceptions.Rows[0].Selected = true;<br />
17. SetUpDataGridView(0);<br />
18.<br />
19.<br />
20. private void dgvExceptions_CellContentClick(object sender, DataGridViewCellEventArgs e)<br />
21. {<br />
22. SetUpDataGridView(e.RowIndex);<br />
23. }<br />
24.<br />
25. private void SetUpDataGridView(int p)<br />
26. {<br />
27. DataGridViewRow row = dgvExceptions.Rows[p];<br />
28. txtExceptionId.Text = row.Cells[0].Value.ToString();<br />
29. txtConnection.Text = row.Cells[1].Value.ToString();<br />
30. txtExceptionType.Text = row.Cells[6].Value.ToString();<br />
31. txtDateOccurred.Text = row.Cells[2].Value.ToString();<br />
32. txtClass.Text = row.Cells[3].Value.ToString();<br />
33. txtModule.Text = row.Cells[4].Value.ToString();<br />
34. txtMethod.Text = row.Cells[5].Value.ToString();<br />
35. txtMessage.Text = row.Cells[7].Value.ToString();<br />
36. }<br />