DataGridView 添加鼠标右键选择行

1、设置选择模式

this.DataGridView_1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;

2、添加CellMouseDown事件

if (e.Button == MouseButtons.Right)
{
        if (e.RowIndex >= 0)
        {
                DataGridView_1.ClearSelection();
                DataGridView_1.Rows[e.RowIndex].Selected = true;
                DataGridView_1.CurrentCell = dgItems.Rows[e.RowIndex].Cells[e.ColumnIndex];
        }
}
posted @ 2017-07-12 13:48  谷仁儿  阅读(1370)  评论(0编辑  收藏  举报