DataGridView - Select on Right Mouse Click

Maggio 3rd, 2007

Description: Select cell when doing a right mouse click on a data cell.

Link: http://www.codekeep.net/snippets/18e913e2-8791-40d5-98e2-08579083445a.aspx

private void dataGrid1_MouseDown(object sender, MouseEventArgs e)

{

DataGridView.HitTestInfo Hti;

if (e.Button == MouseButtons.Right)

{

Hti = dataGrid1.HitTest(e.X, e.Y);

if (Hti.Type == DataGridViewHitTestType.Cell)

{

if (!((DataGridViewRow)(dataGrid1.Rows[Hti.RowIndex])).Selected)

{

dataGrid1.ClearSelection();

((DataGridViewRow)dataGrid1.Rows[Hti.RowIndex]).Selected = true;

}

}

}

}

  • .NET
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.