View Code
1 private void DgvConsignmentBills_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
2 {
3 if (e.Button == MouseButtons.Right)
4 {
5 if (e.RowIndex >= 0)
6 {
7 this.DgvConsignmentBills.ClearSelection();
8 this.DgvConsignmentBills.Rows[e.RowIndex].Selected = true;
9 this.DgvConsignmentBills.CurrentCell = this.DgvConsignmentBills.Rows[e.RowIndex].Cells[e.ColumnIndex];
10 contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
11 }
12 }
2 {
3 if (e.Button == MouseButtons.Right)
4 {
5 if (e.RowIndex >= 0)
6 {
7 this.DgvConsignmentBills.ClearSelection();
8 this.DgvConsignmentBills.Rows[e.RowIndex].Selected = true;
9 this.DgvConsignmentBills.CurrentCell = this.DgvConsignmentBills.Rows[e.RowIndex].Cells[e.ColumnIndex];
10 contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
11 }
12 }
注意:使用次代码需要江datagridview的关联右键菜单去掉。不要在设计器中进行设计。