110,538
社区成员
发帖
与我相关
我的任务
分享
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if (e.RowIndex != -1 && dataGridView1.Rows[e.RowIndex].Cells[0] != null)
{
Point p = dataGridView1.PointToClient(Cursor.Position);
this.contextMenuStrip1.Show(dataGridView1, p);
}
}
}
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
Point p=dataGridView1.PointToClient(MousePosition);
System.Windows.Forms.DataGridView.HitTestInfo hitInfo=dataGridView1.HitTest(p.X, p.Y);
if (hitInfo.RowIndex < 0 || hitInfo.ColumnIndex < 0||(dataGridView1[hitInfo.ColumnIndex, hitInfo.RowIndex].Value == null ))
{
e.Cancel = true;
}
}