1. 程式人生 > >Winform DataGridView鼠標右鍵選擇列

Winform DataGridView鼠標右鍵選擇列

選擇列 tag () return right clear clas mage cell

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]; } }





Winform DataGridView鼠標右鍵選擇列