I want to select a row of datagridview when user will right click on a particular cell.
How I can do that?
I tried the code..
private void grid_users_MouseClick(object sender, MouseEventArgs e)
{
if(e.Button == MouseButtons.Right)
{
//the control goes here..but i am not getting how I can select a row
} }
or shall I go for another event?
How to select a row in DataGridView control on right click of mouse
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.

Kirtan PatelRank #292 · 8.6K reputationPosted May 19, 2009, 5:45 AM EDT
Here i Assume that you will Click First Cell of the Row and Whole row will be selected
Here is Code for It
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
int rowIndex = e.RowIndex;
if (e.ColumnIndex == 0)
{
dataGridView1.Rows[rowIndex].Selected = true;
}
}
}