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
2115
ToolsCollectionBase owning PopupMenu root tool is invalid or null when removing a Tool from the ParentCollection
posted

In which cases can I get the error:

    ToolsCollectionBase owning PopupMenu root tool is invalid or null.

when removing a tool from it's own ParentCollection with following code:

var parentCollection = this.Tool.ParentCollection;
if (parentCollection != null)
{
    parentCollection.Remove(this.Tool);
}

Creating the tool is done fairly simple:

var popupMenuTool = new PopupMenuTool(dropNode.ItemKey);
popupMenuTool.SharedProps.Caption = dropNode.Text;

I am using a rather undocumented method to insert the Tool in the PopupMenuTool as I am creating a custom RibbonCustomizationDialog. Maybe there's a problem there... ( --> InsertToolForRibbonCustomization). 

The full version of the code is:

// Remove the Tool from the ToolbarsManager and the dropNode from the UltraTree so we
// can insert a PopupMenuTool instead.
var dropNodeIndex = parentRibbonGroupNode.Group.Tools.IndexOf(dropNode);
parentRibbonGroupNode.Group.Tools.Remove(dropToolNode.Tool);
dropNode.Remove();
 
// Create PopupMenuTool from DropNode
var popupMenuTool = new PopupMenuTool(dropNode.ItemKey);
popupMenuTool.SharedProps.Caption = dropNode.Text;
 
// Insert PopupMenuTool in the RibbonGroup at index 0
parentRibbonGroupNode.Group.Tools.InsertToolForRibbonCustomization(
    dropNodeIndex,
    popupMenuTool,
    isCopy,
    excludedToolKeys);
 
// Create UltraTreeNode from PopupMenuTool
var popupMenuNode = this.CreateNodeForTool(popupMenuTool, truenulltrue);
if (popupMenuTool.GetIsHiddenByMdiMerge())
{
    ((ToolNode)popupMenuNode).ForceVisible = isCopy;
    popupMenuNode.Visible = true;
    this.refreshMerge = true;
}
 
// Insert the popupMenuNode in the UltraTree
parentRibbonGroupNode.Nodes.Insert(0, popupMenuNode);
 
// Now that the dropNode Tool has been converted to a PopupMenuTool, add the dragNode
// to the PopupMenuTool Node. First insert the Tool, then insert the UltraTreeNode.
 
// Insert the Tool
tool = popupMenuTool.Tools.InsertToolForRibbonCustomization(
    0,
    (dragNode as ToolNode).Tool,
    isCopy,
    excludedToolKeys);
 
// Create an UltraTreeNode from the Tool.
newUltraTreeNode = this.CreateNodeForTool(tool, truenulltrue);
if (tool.GetIsHiddenByMdiMerge())
{
    ((ToolNode)newUltraTreeNode).ForceVisible = isCopy;
    newUltraTreeNode.Visible = true;
    this.refreshMerge = true;
}
 
// Insert the UltraTreeNode
popupMenuNode.Nodes.Insert(0, newUltraTreeNode);

What I'm actuall trying to do is that when a ButtonTool(A) is dragged over the middle of another ButtonTool(B), then B gets transformed into a PopupMenuTool and the ButtonTool A gets added to that PopupMenuTool. The ButtonTool B is removed. 

Thx, Lieven Cardoen