深秋

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
现在就只发现使用DataGridView的CellMouseDown事件来实现右键选中行。您是否还有更好的方法呢?一起探讨!!!
private void dgvTest_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            if (e.RowIndex == -1 || e.ColumnIndex == -1)
                return;

            if (e.Button == MouseButtons.Right)
            {
                    DataGridView dgv = (DataGridView)sender;
                    dgv.ClearSelection();
                    //使用这条语句需要设置MultiSelect=false
                    //dgv.CurrentRow.Selected = false;
                    dgv.Rows[e.RowIndex].Selected = true;
            }
        }
posted on 2011-03-08 20:25  深秋  阅读(565)  评论(0编辑  收藏  举报