0

我有一个带有 dgv1.CellClick 的 DataGridView。

使用鼠标左键单击单元格时会显示上下文菜单。发生这种情况时,它还会将位置设置为当前单元格,但是当我单击鼠标右键时,上下文菜单条也会显示出来。我想在单击鼠标右键时禁用或隐藏上下文菜单。

我试过了:

    private void dgv1_MouseClick(object sender, MouseEventArgs e)
    {
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
            cms1.Hide();
    }

这没有用。

有人有建议吗?

4

4 回答 4

3
    private MouseButtons e_Button = new MouseButtons();
    private void dgv1_MouseDown(object sender, MouseEventArgs e)
    {
        e_Button = e.Button;
    }

    private void cms1_Opening(object sender, CancelEventArgs e)
    {
        if (e_Button == System.Windows.Forms.MouseButtons.Right)
            e.Cancel = true;
    }
于 2012-11-16T21:10:57.407 回答
0

也许有了这个:

private void dgv1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)  {
        if ((e.Button != Windows.Forms.MouseButtons.Right)) {
            cms1.Show(datagridview, e.Location);
            }
        }
    }
于 2012-11-16T11:39:41.880 回答
0

试试这个

private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    e.Control.ContextMenu = new ContextMenu();
}
于 2012-11-16T11:42:51.717 回答
0
private void dataGridViewExample_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
    e.Control.ContextMenu = new ContextMenu();
}
于 2012-11-16T11:44:18.577 回答