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        }
posted @ 2006-08-07 10:35  Bireyou  阅读(4598)  评论(8编辑  收藏  举报