2011-04-21 72 views
0

我是一個使用Infragistics的新手。我試圖將上下文菜單添加到UltraWinGrid中的特定行/列,但我無法做到這一點。看起來像向網格添加上下文菜單很簡單,但將其添加到特定的行/列並不是直截了當的。你能告訴我如何做到這一點?向UltraWinGrid添加行特定的上下文菜單

+0

你可以閱讀下面的文章http://help.infragistics.com/Help/NetAdvantage/WinForms/2011.2/CLR2.0/html/WinGrid_Using_the_WinGrid_ClickCell_Event_to_Show_a_Context_Menu.html – serhio 2013-03-15 14:23:49

回答

3

您可以向窗體添加上下文菜單或控制網格所在的位置,並且只在需要該菜單的行/單元格上的網格中單擊鼠標右鍵時才顯示該菜單。

下面是一個例子,雖然它不漂亮。

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(); 
    } 
    } 
} 
+0

你可以給樣品你正在嘗試說? – Aanandi 2011-05-20 20:51:22

+0

有幫助嗎?讓我知道是否需要更多解釋。 – 2011-05-24 21:03:53

0

MouseDown不起作用。請使用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(); 
       } 

      } 
     } 
    } 
} 
+0

MouseDown不起作用。請使用MouseUp。 – user6348094 2016-05-17 22:57:06

+0

請檢查此[URL](http://stackoverflow.com/help)它將有助於提高您的內容質量 – 2016-05-17 23:20:22

相關問題