DataGridView - Select on Right Mouse Click
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;
}
}
}
}






