We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to sort the contextmenu items in WinForms TabbedGroupedMDIManager?

Platform: WinForms |
Control: TabbedGroupedMDIManager |
.NET Framework: 4

Sort the context menu

We can sort the context menu items in the TabbedMDIManager by handling the BeforePopup event of ContextMenuItem. In this event we are getting the context menu items using ArrayList and perform sorting using CustomComparerItems class which is inherited from ICompare interface. The following code demonstrates the same.


BarItem item = new BarItem();
item.Text = "CustomItem";
BarItem item2 = new BarItem();
item2.Text = "ArrangeItem";
BarItem item3 = new BarItem();
item3.Text = "OrderItem";
Form2 form2 = new Form2();
form2.MdiParent = this;
Form2 form3 = new Form2();
form3.MdiParent = this;
form3.Text = "Form3";
//Add Custom context menu items
this.tabbedGroupedMDIManager1.ContextMenuItem.BeforePopup += new CancelEventHandler(ContextMenuItem_BeforePopup);
void ContextMenuItem_BeforePopup(object sender, CancelEventArgs e)
  ArrayList items = new ArrayList();
  foreach (object contextItem in this.tabbedGroupedMDIManager1.ContextMenuItem.Items)
  //For ContextMenuItem sorting
  items.Sort(new CustomComparerItems());
  foreach (object item in items)
public class CustomComparerItems : IComparer
  Comparer compar = new Comparer(System.Globalization.CultureInfo.CurrentCulture);
  public int Compare(object first, object second)
    string item1 = (first as BarItem).Text.ToString();
    string item2 = (second as BarItem).Text.ToString();
    return compar.Compare(item1, item2);


'For Context Menu Sorting
AddHandler tabbedGroupedMDIManager1.ContextMenuItem.BeforePopup, AddressOf ContextMenuItem_BeforePopup
Dim item As New BarItem()
item.Text = "CustomItem"
Dim item2 As New BarItem()
item2.Text = "ArrangeItem"
Dim item3 As New BarItem()
item3.Text = "OrderItem"
Dim form2 As New Form2()
form2.MdiParent = Me
Dim form3 As New Form2()
form3.MdiParent = Me
form3.Text = "Form3"
'Add Custom context menu items
Private Sub ContextMenuItem_BeforePopup(ByVal sender As Object, ByVal e As CancelEventArgs)
  Dim items As New ArrayList()
  For Each contextItem As Object In Me.tabbedGroupedMDIManager1.ContextMenuItem.Items
  Next contextItem
  'For ContextMenuItem sorting
  items.Sort(New CustomComparerItems())
  For Each item As Object In items
  Next item
End Sub
Public Class CustomComparerItems
  Implements IComparer
  Private compar As New Comparer(System.Globalization.CultureInfo.CurrentCulture)
  Public Function Compare(ByVal first As Object, ByVal second As Object) As Integer    Implements IComparer.Compare
    Dim item1 As String = (TryCast(first, BarItem)).Text.ToString()
    Dim item2 As String = (TryCast(second, BarItem)).Text.ToString()
    Return compar.Compare(item1, item2)
  End Function
End Class



Show the sort context menu items



2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile