1、设置DataGridView 的属性 SelectionMode
SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
2、设置事件CellMouseDown
private void dgvResult_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { if (e.RowIndex == -1 || e.ColumnIndex == -1) return; if (e.Button == System.Windows.Forms.MouseButtons.Right) { this.dgvResult.ClearSelection(); this.dgvResult.CurrentRow.Selected = false; this.dgvResult.Rows[e.RowIndex].Selected = true; this.dgvResult.CurrentCell = dgvResult.Rows[e.RowIndex].Cells[e.ColumnIndex]; } }
时间: 2024-10-10 13:03:39