单击单元格,禁用Datagrid中的上下文菜单 [英] Disable a context menu in Datagrid on cell click

查看:68
本文介绍了单击单元格,禁用Datagrid中的上下文菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void cmsCoords_Opening(object sender, CancelEventArgs e)
        {
            cmsCoords.Items[0].Enabled = true ;
            cmsCoords.Items[1].Enabled = true;

        }

        private void dgvErrorTable_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                DataGridView.HitTestInfo hti = dgvErrorTable.HitTest(e.X, e.Y);
                dgvErrorTable.ClearSelection();
                dgvErrorTable.Rows[hti.RowIndex].Selected = true;
                cmsCoords.Show(dgvErrorTable, e.Location);
            }

        }



我想在任何单元格单击上禁用Datagrid中的上下文菜单.

我只需要单击上下文菜单.
但是我的代码也适用于任何单元格单击.

谁能让我知道如何仅针对行点击启用它.
附件是我的代码.


谢谢
Sheethal


Hi,
I want to disable the context menu in Datagrid on any cell click.

I want the context menu for only row click.
But my code is working for any cell click also.

Can anyone let me know how to enable it for only row click.
Attached is my code.


Thanks
Sheethal

推荐答案

如果这听起来有误,请更正我:单元格是行的一部分.对?
据我所知,应该如此.现在,单击一个单元格意味着单击一行.您所需要做的就是处理单击,以便可以在行级别进行操作.
Correct me if this sounds wrong: Cells are part of row. Right?
As much I know, it should be. Now, clicking a cell means clicking a row. All you need is to handle the click such that you can do operations at row level.


if (hti.Type == DataGridViewHitTestType.Cell)
{
    cmsCoords.Visible = false;
}
else
{
    cmsCoords.Show(dgvErrorTable, e.Location);
}


实际上,我的意思是,当我单击数据网格中的仅一行时,我需要查看上下文菜单.(datagrid的左侧)
并非在所有单元格上都

我已经按照附件更改了代码,现在可以正常工作了.


Actually I meant like I need to view the context menu when onclick on only row in data grid.(left part of datagrid)
not on all cells

I changed my code as per attachment and its working fine now.


这篇关于单击单元格,禁用Datagrid中的上下文菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆