Home
Manage Your Code
Snippet: DataGridView - Select on Right Mouse Click (C#)
Title: DataGridView - Select on Right Mouse Click Language: C#
Description: Select cell when doing a right mouse click on a data cell. Views: 912
Author: James Taylor Date Added: 5/2/2007
Copy Code  
1private void dataGrid1_MouseDown(object sender, MouseEventArgs e)
2
3{
4
5DataGridView.HitTestInfo Hti;
6
7if (e.Button == MouseButtons.Right)
8
9{
10
11Hti = dataGrid1.HitTest(e.X, e.Y);
12
13if (Hti.Type == DataGridViewHitTestType.Cell)
14
15{
16
17if (!((DataGridViewRow)(dataGrid1.Rows[Hti.RowIndex])).Selected)
18
19{
20
21dataGrid1.ClearSelection();
22
23((DataGridViewRow)dataGrid1.Rows[Hti.RowIndex]).Selected = true;
24
25}
26
27}
28
29}
30
31}