Back to Devexpress

BaseView.DocumentSelectorCustomSortItems Event

windowsforms-devexpress-dot-xtrabars-dot-docking2010-dot-views-dot-baseview-3c7ebb4f.md

latest4.0 KB
Original Source

BaseView.DocumentSelectorCustomSortItems Event

Allows you to manually sort documents and dock panels displayed within the Document Selector.

Namespace : DevExpress.XtraBars.Docking2010.Views

Assembly : DevExpress.XtraBars.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
public event DocumentSelectorCustomSortItemsEventHandler DocumentSelectorCustomSortItems
vb
Public Event DocumentSelectorCustomSortItems As DocumentSelectorCustomSortItemsEventHandler

Event Data

The DocumentSelectorCustomSortItems event's data class is DevExpress.XtraBars.Docking2010.Views.DocumentSelectorCustomSortItemsEventArgs.

Remarks

To sort a document selector’s items manually, you need to create the IComparer class descendant and override its Compare method. This method compares two items and returns -1 , 0 or 1 depending on the result. This method will be used to compare all documents or dock panels within the document selector. Then, assign this custom comparer to the e.DockPanelComparer or e.DocumentComparer property to use it for dock panel or document sorting respectively.

The following code illustrates how to sort dock panels by their captions in reverse alphabetical order. The result is shown in the image below.

csharp
public partial class myApplicationForm : DevExpress.XtraEditors.XtraForm {
    public frmMain() {
        InitializeComponent();
        tabbedView.DocumentSelectorProperties.ItemSortMode = Docking2010.Customization.ItemSortMode.Custom;
    }
    //. . .
    private void tabbedView_DocumentSelectorCustomSortItems(object sender, DocumentSelectorCustomSortItemsEventArgs e) {
       e.DockPanelComparer = new DescendingPanelTextComparer();
    }
}

public class DescendingPanelTextComparer : IComparer<DockPanel> {
    public int Compare(DockPanel panel1, DockPanel panel2) {
        if (string.Equals(panel1.Text, panel2.Text)) return 0;
        if (panel1.Text.CompareTo(panel2.Text) == 1) return -1;
        else return 1;
    }
}
vb
Public Partial Class myApplicationForm
    Inherits DevExpress.XtraEditors.XtraForm
    Public Sub New()
        InitializeComponent()
        tabbedView.DocumentSelectorProperties.ItemSortMode = Docking2010.Customization.ItemSortMode.[Custom]
    End Sub
    '. . .
    Private Sub tabbedView_DocumentSelectorCustomSortItems(sender As Object, e As DocumentSelectorCustomSortItemsEventArgs)
        e.DockPanelComparer = New DescendingPanelTextComparer()
    End Sub
End Class

Public Class DescendingPanelTextComparer
    Implements IComparer(Of DockPanel)
    Public Function Compare(panel1 As DockPanel, panel2 As DockPanel) As Integer
        If String.Equals(panel1.Text, panel2.Text) Then
            Return 0
        End If
        If panel1.Text.CompareTo(panel2.Text) = 1 Then
            Return -1
        Else
            Return 1
        End If
    End Function
End Class

Note

The DocumentSelectorCustomSortItems event fires only if the View’s DocumentSelectorProperties.ItemSortMode property equals Custom.

See Also

BaseView Class

BaseView Members

DevExpress.XtraBars.Docking2010.Views Namespace