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
85
Dynamic Popupmenus in MDI Child
posted

Hi

I'm using Office2007 UI (Ribbon) in an MDI application. In one of the child forms I want to add buttons dynamically to a popupmenu, but they don't show up. I've used the following code:

        private void toolbarsManager_BeforeToolDropdown(object sender, Infragistics.Win.UltraWinToolbars.BeforeToolDropdownEventArgs e)
        {
                    string key = "MyKey";

                    PopupMenuTool tool = (PopupMenuTool)e.Tool;
                    ButtonTool button = new ButtonTool(key);
                    button.SharedProps.Caption = "Name";

                    toolbarsManager.Tools.Add(button);
                    tool.Tools.AddTool(key);

        }

The toolbarsManager is the MDI Child toolbars manager, but I've tried to use the toolbarsManager.MDIParentManger and setting the optional parameter in AddTool to true without success.

UPDATE: If switching child forms back and forth, the dynamically added tools is shown the first time, but then not until you switch forms again. This feels a little bit like a bug to me.

Any help would be appricated. Thanks, Eric

Parents
No Data
Reply
  • 110
    posted

    I am having the same problem. I've come up with this workaround, but you'll get a flicker on the child ribbon if it is visible:

     

    RibbonTab selTab = null;
    if (toolbarManager.MdiParentManager != null)
    {
        selTab = toolbarManager.MdiParentManager.Ribbon.SelectedTab;
    }
    toolbarManager.RefreshMerge();
    if (selTab != null)
    {
        toolbarManager.MdiParentManager.Ribbon.SelectedTab = selTab;
    }

     

    There ought to be a better way to tell a tool to be redrawn (the problem is that the tools *are* dynamically added, but don't shown up until the child tool is told to be redrawn. I bet it's possible to find the PopupMenu tool's representation on the parent ribbon and add the tools *there* and have it refresh right away without needing that workaround, but I haven't figured out how to do it.

     

    Still, I agree that it seems like a bug that dynamically adding tools to a top-level/parent popupmenu works fine, but we have this issue with child ribbons.

Children