OT: Adding to a popup menu

OT: Adding to a popup menu

Old forum URL: forums.lhotka.net/forums/t/3692.aspx


ajj3085 posted on Thursday, October 11, 2007

Hi,

I'm using the Infragistics UltralToolbarsManager for the context menu on the UltraGrid.

I have some business objects which have an API that allows the UI to query the objects and build a part of the menu.

My code to add the items is this:
        // optionsTool always exists on the menu
        private void BuildOptionsMenu( ILineItem item, PopupMenuTool optionsTool ) {
            List<ToolBase> existingTools;
            ToolBase newTool;

            existingTools = new List<ToolBase>();
            foreach ( ToolBase tool in optionsTool.Tools ) {
                existingTools.Add( tool );
            }
            optionsTool.Tools.Clear();
            foreach ( ToolBase tool in existingTools ) {
                ultraToolbarsManager1.Tools.Remove( tool );
            }

            foreach ( LineItemOption option in item.GetLineItemOptions() ) {
                newTool = CreateTool( item, option );
                newTool.SharedProps.DisplayStyle = ToolDisplayStyle.TextOnlyAlways;
                newTool.SharedProps.Caption = option.Description;

                ultraToolbarsManager1.Tools.Add( newTool );
                optionsTool.Tools.AddTool( newTool.Key );
            }
        }

        private ToolBase CreateTool( ILineItem item, LineItemOption option ) {
            ToolBase result;
            StateButtonTool button;

            if ( option.ValueType == typeof( bool ) ) {
                button = new StateButtonTool( option.Key );
               
                if ( (bool)item.GetOption( option.Key ) ) {
                    button.Checked = true;
                }

                result = button;
            }
            else {
                throw new Exception();
            }

            return result;
        }

No items ever appear on the popupmenu though.. any ideas what I'm doing wrong?  This is similar to some sample code from Infragistics that does work, and I can't see any different exception I'm not setting any icons.

Copyright (c) Marimer LLC