ToolStripManager.RevertMerge Method (ToolStrip)


Undoes a merging of two ToolStrip objects, returning the specified ToolStrip to its state before the merge and nullifying all previous merge operations.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public static bool RevertMerge(
	ToolStrip targetToolStrip


Type: System.Windows.Forms.ToolStrip

The ToolStripItem for which to undo a merge operation.

Return Value

Type: System.Boolean

true if the undoing of the merge is successful; otherwise, false.

The ToolStrip.AllowMerge property must be set to true for both ToolStrip objects, or this method returns false.

The following code example undoes the merging of menu items. This example is part of a larger example available in the ToolStripManager class overview.

private MergeSample CurrentSample
    get { return currentSample; }
        if (currentSample != value)
            bool resetRequired = false;

            if (currentSample == MergeSample.MatchOnly)
                resetRequired = true;
            currentSample = value;
            // Undo previous merge, if any.
            ToolStripManager.RevertMerge(cmsBase, cmsItemsToMerge);
            if (resetRequired)

            switch (currentSample)
                case MergeSample.None:
                case MergeSample.Append:
                    ScenarioText = "This sample adds items to the end of the list using MergeAction.Append.\r\n\r\nThis is the default setting for MergeAction. A typical scenario is adding menu items to the end of the menu when some part of the program is activated.";
                case MergeSample.InsertInSameLocation:
                    ScenarioText = "This sample adds items to the middle of the list using MergeAction.Insert.\r\n\r\nNotice here how the items are added in reverse order: four, three, two, one. This is because they all have the same merge index.\r\n\r\nA typical scenario is adding menu items to the middle or beginning of the menu when some part of the program is activated. ";
                case MergeSample.InsertInSameLocationPreservingOrder:
                    ScenarioText = "This sample is the same as InsertInSameLocation, except the items are added in normal order by increasing the MergeIndex of \"two merged items\" to be 3, \"three merged items\" to be 5, and so on.\r\n  You could also add the original items backwards to the source ContextMenuStrip.";
                case MergeSample.ReplacingItems:
                    ScenarioText = "This sample replaces a menu item using MergeAction.Replace. Use this for the MDI scenario where saving does something completely different.\r\n\r\nMatching is based on the Text property. If there is no text match, merging reverts to MergeIndex.";
                case MergeSample.MatchOnly:
                    ScenarioText = "This sample adds only the subitems from the child to the target ContextMenuStrip.";

            // Reapply with the new settings.
            ToolStripManager.Merge(cmsItemsToMerge, cmsBase);

.NET Framework
Available since 2.0
Return to top