右击DataGrilView行事件

时间:2021-12-19 20:36:28
        private void dgvEmployee_MouseDown(object sender, MouseEventArgs e)
        {
            DataGridView.HitTestInfo rows = this.dgvEmployee.HitTest(e.X, e.Y);
            if (e.Button == MouseButtons.Right)
            {
                if (rows.RowIndex > -1 && rows.ColumnIndex > -1)
                {
               
                    this.dgvEmployee.ClearSelection();
                    this.dgvEmployee.Rows[rows.RowIndex].Selected = true;
                    this.dgvEmployee.CurrentCell = this.dgvEmployee.Rows[rows.RowIndex].Cells[rows.ColumnIndex];

                    this.cmnuEmployee_Modify.Enabled = true;
                    this.cmnuEmployee_Score.Enabled = true;
                }
                else
                {
                    this.cmnuEmployee_Modify.Enabled = false;
                    this.cmnuEmployee_Score.Enabled = false;
                }
            }
        }