Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
48
Adding row/column specific contextmenu to an UltraWinGrid
posted

I've an UltraGrid like this:

  Column1      Column2      Column3                                                
----------
    0                    ABC                  ABB
    0                    XYZ                   XXZ
    1                    CCB                 AAA
    2                    QWE                ASD
    1                    ASX                  ZAW

I'm trying to add context menu to a specific row/column in UltraWinGrid, i.e, if column1 = 0 then contextmenu1, if coumn1 =1 then contextmenu2, if column1 = 2 then contextmenu3 ( all the 3 contextmenus are have different menu items.)
 Can you please help???

 

Parents
  • 3707
    Verified Answer
    posted

    Use the MouseDown event of the UltraGrid. Then you can do something such as:

    ContextMenu defaultContextMenu;
    public frmMain()
    {
        InitializeComponent();
        defaultContextMenu = ultraGrid1.ContextMenu;
    }
    private void ultraGrid1_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Right)
        {
            UIElement element = ultraGrid1.DisplayLayout.UIElement.ElementFromPoint(e.Location);
            if (element == null || element.Parent == null)
                return;
            Infragistics.Shared.ISelectableItem theitem = element.SelectableItem;
            if (theitem is UltraGridCell)
            {
                ultraGrid1.ActiveRow = ((UltraGridCell)theitem).Row;
                ultraGrid1.ActiveCell = theitem as UltraGridCell;
                switch (ultraGrid1.ActiveCell.Column.Key)
                {
                    case "Column1":
                        ultraGrid1.ContextMenu = contextMenu1;
                        break;
                    case "Column2":
                        ultraGrid1.ContextMenu = contextMenu2;
                        break;
                    case "Column3":
                        ultraGrid1.ContextMenu = contextMenu3;
                        break;
                    default:
                        ultraGrid1.ContextMenu = defaultContextMenu;
                        break;
                }
            }
            else
            {
                ultraGrid1.ContextMenu = defaultContextMenu;
            }
        }
    }

Reply Children
No Data