How do I select a complete dataGridView Row when the user clicks a cell of that row?
You need to set datagridview's SelectionMode
to FullRowMode
.
Note: In Visual Studio 2013 with .NET 4.5 the property is called FullRowSelect
.
If you want the row selected programatically, you would use the datagridview's cell click event: shown in VB.net and C#
VB.Net
Private Sub dgvGrid_CellClick(sender as System.Object, e as System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvGrid.CellClick
If e.RowIndex < 0 Then
Exit Sub
End If
intIndex = e.RowIndex
dgvGrid.Rows(intIndex).Selected = True
Exit Sub
C#
private void dgvRptTables_CellClick(System.Object sender, System.Windows.Forms.DataGridViewCellEventArgs e)
{
if (e.RowIndex < 0) {
return;
}
int index = e.RowIndex;
dgvGrid.Rows[index].Selected = true;
}
In the DataGridView properties, Set
- MultiSelect -> True
- SelectionMode -> FullRowSelect