【问题标题】:Context menu appears on the blank space as well as on the Ultra grid header when right click右键单击时,上下文菜单出现在空白区域以及 Ultra 网格标题上
【发布时间】:2012-10-04 17:09:55
【问题描述】:

右键单击 Ultragrid (Infragistics) 的空白部分或 C# 上下文菜单中的标题出现并且不执行任何操作。当点击落在一行上时,我怎样才能只显示上下文菜单?

所以我正在做一个项目,我有一个超网格,我在其中放置了一个上下文菜单,当有人在网格中单击鼠标右键时,菜单就会出现(删除)。但是右键单击时,上下文菜单会出现在空白区域以及 Ultra 网格标题上,我希望它在单击时出现在一行上。

【问题讨论】:

  • 您能补充更多信息吗?就目前而言,人们可能很难帮助您...
  • 你有任何可以包含的代码吗?

标签: c# contextmenu infragistics ultrawingrid


【解决方案1】:

这需要在您的环境中进行测试,但我认为它可以工作。
诀窍在于使用 MouseDown 事件检查鼠标位置下的单元格(如果有),并且仅当我们在测试 IsDataRow 属性的 DataRow 单元格上方时才分配 ContextMenu。

private void grid_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
    UltraGridCell currentCell = null;
    grid.ContextMenu = null;

    if (e.Button == MouseButtons.Right)
    {
        Point ulPoint = new Point(e.X, e.Y);
        UIElement el = grid.DisplayLayout.UIElement.ElementFromPoint(ulPoint); 
        if (el != null)
            currentcell = (UltraGridCell)el.GetContext(typeof(UltraGridCell)); 
        if (currentcell != null && currentCell.Row.IsDataRow == true)
        {
            grid.ActiveCell = currentcell;
            grid.ContextMenu = menuPopup;
        }
    }
}

【讨论】:

    猜你喜欢
    • 2012-01-01
    • 2016-02-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-27
    • 2010-12-15
    • 2017-04-22
    • 1970-01-01
    相关资源
    最近更新 更多