将行特定上下文菜单添加到 UltraWinGrid

发布于 2024-11-03 08:15:24 字数 147 浏览 1 评论 0原文

我是使用 Infragistics 的新手。我正在尝试将上下文菜单添加到 UltraWinGrid 中的特定行/列,但我无法做到这一点。看起来将上下文菜单添加到网格很简单,但将其添加到特定的行/列并不简单。你能告诉我该怎么做吗?

I'm a newbie using Infragistics. I'm trying to add context menu to a specific row/column in UltraWinGrid, which I'm not able to. Looks like adding context menu to the grid is simple but adding it to a specific row/column is not straight forward. Can you please tell me how to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

饭团 2024-11-10 08:15:24

您可以将上下文菜单添加到表单或控件中,您的网格将驻留在其中,并且仅当他们在需要该菜单的行/单元格上右键单击网格时才显示它。

这是一个例子,尽管它并不漂亮。

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

    Point point = new System.Drawing.Point(e.X, e.Y);
    UIElement uiElement = ((UltraGridBase) sender).DisplayLayout.UIElement.ElementFromPoint(point);
    UltraGridCell cell = (UltraGridCell) uiElement.GetContext(typeof (UltraGridCell));  

    if (cell != null && UseThisContextMenu(cell))
    {
      ContextMenu.Show();
    }
  }
}

You could add a context menu to the form or control your grid will reside in and only display it in when they right click in the grid over the rows/cells that need that menu.

Here's an example, though it's not pretty.

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

    Point point = new System.Drawing.Point(e.X, e.Y);
    UIElement uiElement = ((UltraGridBase) sender).DisplayLayout.UIElement.ElementFromPoint(point);
    UltraGridCell cell = (UltraGridCell) uiElement.GetContext(typeof (UltraGridCell));  

    if (cell != null && UseThisContextMenu(cell))
    {
      ContextMenu.Show();
    }
  }
}
梦行七里 2024-11-10 08:15:24

鼠标按下不起作用。请使用鼠标向上键。

private void UltraGrid1_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right)
        {

            Point point = new System.Drawing.Point(e.X, e.Y);
            UIElement uiElement = ((UltraGridBase)sender).DisplayLayout.UIElement.ElementFromPoint(point);
            UltraGridCell cell = (UltraGridCell)uiElement.GetContext(typeof(UltraGridCell));

            if (cell.Band.Index == 0)
            {
                if (cell.Column.Key.Equals("ColumnToShow"))
                {
                    contextMenuStrip.Show();
                }
                else
                {
                    contextMenuStrip.Hide();
                }

            }
        }
    }
}

MouseDown does not work. Please use MouseUp.

private void UltraGrid1_MouseUp(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right)
        {

            Point point = new System.Drawing.Point(e.X, e.Y);
            UIElement uiElement = ((UltraGridBase)sender).DisplayLayout.UIElement.ElementFromPoint(point);
            UltraGridCell cell = (UltraGridCell)uiElement.GetContext(typeof(UltraGridCell));

            if (cell.Band.Index == 0)
            {
                if (cell.Column.Key.Equals("ColumnToShow"))
                {
                    contextMenuStrip.Show();
                }
                else
                {
                    contextMenuStrip.Hide();
                }

            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文