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
420
Programmatically altering the ContextMenuUltra
posted

I have a hierarchical grid with two child bands attached to a parent band.

Each level needs a different context menu.  Any way to, on row click, change the ContextMenuUltra to a different PopupMenuTool? 

The other option that would be ok would be for us to be able to hide just that popup menu's instance of certain tool items (we would disable the main toolbars instead of hide them)

 

Parents
  • 69832
    Verified Answer
    Offline posted

    You could do either...I wasn't sure which event you were referring to, but typically one handles MouseDown and configures a context menu (or PopupMenuTool) based on the entity at the current cursor position, so that when it is displayed on the MouseUp, it has the appropriate menu items. In the following example, the menu is changed based on the band in which the row at the current cursor position resides:

    this.ultraGrid1.MouseDown += new MouseEventHandler(ultraGrid1_MouseDown);
    void ultraGrid1_MouseDown(object sender, MouseEventArgs e)
    {
        //  Get the UltraGridRow at the current cursor position
        UltraGrid grid = sender as UltraGrid;
        UIElement controlElement = grid.DisplayLayout.UIElement;
        UIElement elementAtPoint = controlElement.ElementFromPoint( e.Location );
        if ( elementAtPoint != null )
        {
            UltraGridRow rowAtPoint = elementAtPoint.GetContext( typeof(UltraGridRow) ) as UltraGridRow;
            if ( rowAtPoint != null )
            {
                UltraGridBand band = rowAtPoint.Band;

                //  Assuming a different PopupMenuTool is defined for each band...
                string menuKey = band.Index == 0 ? "bandZero" : band.Index == 1 ? "bandOne" : "bandTwo";
                this.ultraToolbarsManager1.SetContextMenuUltra( grid, menuKey );
            }
        }

    }

Reply Children
No Data