DataGridView上按右键弹出右键菜单前选中当前行
在VS2005的C# WinForm编程中,有一个DataGridView控件,要在其上按右键弹出右键菜单前选中当前行,可以在CellMouseDown事件中加入如下代码:
1 private void DataGridView1_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
2 {
3 DataGridView1.ClearSelection();
4 DataGridView1.Rows[e.RowIndex].Selected = true;
5 DataGridView1.CurrentCell = DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
6 }
2 {
3 DataGridView1.ClearSelection();
4 DataGridView1.Rows[e.RowIndex].Selected = true;
5 DataGridView1.CurrentCell = DataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
6 }