Reputation: 91
i have a datagridview and i would like the rowheader to correctly select that entire row. Although i thought it should anyway, it does not. i have tried the following but with no luck, can you see something obvious? =P regards, Dave
private void dataGridView2_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
dataGridView2.Rows[e.RowIndex].Selected = true;
}
Upvotes: 2
Views: 1781
Reputation: 13721
Try setting the
DataGridView.MultiSelect=false;
and
DataGridView.SelectionMode = FullRowSelect;
You can read about the MultiSelect Property and SelectionMode Property in the MSDN library linked.
If you want the user to select multiple rows, then set MultiSelect
to true.
DataGridView.MultiSelect=true;
EDIT
And then you can call your event like this:
private void dataGridView2_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
dataGridView2.Rows[e.RowIndex].Selected = true;
}
To select individual cells within the data grid view and select the entire row on row header click, set the selection mode to RowHeaderSelect
DataGridView.SelectionMode = RowHeaderSelect;
The MSDN explanation for RowHeaderSelect
is: Clicking a cell selects it. Clicking a row header selects the entire row.
Upvotes: 4