110,534
社区成员
发帖
与我相关
我的任务
分享
private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
DataGridView.HitTestInfo hit = this.dataGridView1.HitTest(e.X, e.Y);
if (hit.Type == DataGridViewHitTestType.Cell)
{
this.dataGridView1.Rows[hit.RowIndex].Selected = true;
this.contextMenuStrip1.Show(this.dataGridView1, e.X, e.Y);
}
}
}
private void dataGridView1_CellContextMenuStripNeeded(object sender, DataGridViewCellContextMenuStripNeededEventArgs e)
{
dataGridView1.CurrentCell = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
}