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?
Loading
Kirtan PatelPosted May 19, 2009, 9:45 AM
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;
}
}
}