c# datagridview右键选中行

在datagridview中有时需要在右键点击某行的时候就选中它,那么我们只需要在datagridview的CellMonseDown事件中添加如下代码就行:

 if (e.Button == MouseButtons.Right && e.RowIndex > -1 && e.ColumnIndex > -1)

{

      (sender as DataGridView).CurrentRow.Selected = false;

      (sender as DataGridView).Rows[e.RowIndex].Selected = true;

}

原文地址:https://www.cnblogs.com/sczmzx/p/3370961.html