Back to Devexpress

IBaseDocumentSelectorProperties.ItemSortMode Property

windowsforms-devexpress-dot-xtrabars-dot-docking2010-dot-customization-dot-ibasedocumentselectorproperties.md

latest6.1 KB
Original Source

IBaseDocumentSelectorProperties.ItemSortMode Property

Gets or sets order in which Documents and dock panels appear inside the Document Selector.

Namespace : DevExpress.XtraBars.Docking2010.Customization

Assembly : DevExpress.XtraBars.v25.2.dll

NuGet Package : DevExpress.Win.Navigation

Declaration

csharp
ItemSortMode ItemSortMode { get; set; }
vb
Property ItemSortMode As ItemSortMode

Property Value

TypeDescription
DevExpress.XtraBars.Docking2010.Customization.ItemSortMode

An ItemSortMode enumeration value that specifies the order in which Documents and dock panels appear inside the Document Selector.

|

Remarks

The Document Selector stores the Document (and dock panel) activation sequences and arranges its items in the opposite direction. The figure below illustrates the order in which Document Manager’s Documents were activated, and how the Document Selector arranges them.

To change this default order, set the ItemSortMode property to either Alphabetical or Custom. In custom sorting mode, handle the BaseView.DocumentSelectorCustomSortItems event and assign your custom IComparer<BaseDocument> object to the e.DocumentComparer object. You can also create a separate dock panel container and assign it to the e.DockPanelComparer property.

The code sample below illustrates how to implement the custom item order the order in which Documents appear on-screen.

csharp
using DevExpress.XtraBars.Docking2010.Views;
// . . .
tabbedView1.DocumentSelectorProperties.ItemSortMode = DevExpress.XtraBars.Docking2010.Customization.ItemSortMode.Custom;
tabbedView1.DocumentSelectorCustomSortItems += TabbedView1_DocumentSelectorCustomSortItems;

private void TabbedView1_DocumentSelectorCustomSortItems(object sender, DevExpress.XtraBars.Docking2010.Views.DocumentSelectorCustomSortItemsEventArgs e) {
    e.DocumentComparer = new DirectOrderComparer(tabbedView1);
}

// Custom Document comparer

public class DirectOrderComparer : IComparer<BaseDocument> {
    BaseView viewCore;
    List<BaseDocument> activationOrder;
    public DirectOrderComparer(BaseView view) {
        viewCore = view;
        if (view.ActiveDocument == null) return;
        FillActivationOrder(view);
    }
    void FillActivationOrder(BaseView view) {
        activationOrder = new List<BaseDocument>();
        activationOrder.Add(view.ActiveDocument);
        for (int i = view.Documents.IndexOf(view.ActiveDocument) + 1; i < view.Documents.Count; i++) {
            activationOrder.Add(view.Documents[i]);
        }
        for (int i = 0; i < view.Documents.IndexOf(view.ActiveDocument); i++) {
            activationOrder.Add(view.Documents[i]);
        }
        foreach (var item in view.FloatDocuments) {
            activationOrder.Add(item);
        }
    }
    public int Compare(BaseDocument x, BaseDocument y) {
        int xIndex = activationOrder.IndexOf(x);
        int yIndex = activationOrder.IndexOf(y);
        return xIndex.CompareTo(yIndex);
    }
}
vb
Imports DevExpress.XtraBars.Docking2010.Views
' . . .
tabbedView1.DocumentSelectorProperties.ItemSortMode = DevExpress.XtraBars.Docking2010.Customization.ItemSortMode.Custom
AddHandler tabbedView1.DocumentSelectorCustomSortItems, AddressOf TabbedView1_DocumentSelectorCustomSortItems

private void TabbedView1_DocumentSelectorCustomSortItems(Object sender, DevExpress.XtraBars.Docking2010.Views.DocumentSelectorCustomSortItemsEventArgs e)
    e.DocumentComparer = New DirectOrderComparer(tabbedView1)

' Custom Document comparer

public class DirectOrderComparer : IComparer(Of BaseDocument)
    Dim viewCore As BaseView
    Dim activationOrder As List(Of BaseDocument)
    public DirectOrderComparer(BaseView view)
        viewCore = view
        If view.ActiveDocument Is Nothing Then
          Return
        End If
        FillActivationOrder(view)
    void FillActivationOrder(BaseView view)
        activationOrder = New List(Of BaseDocument)()
        activationOrder.Add(view.ActiveDocument)
        For i As Integer = view.Documents.IndexOf(view.ActiveDocument) + 1 To view.Documents.Count - 1
            activationOrder.Add(view.Documents(i))
        Next i
        For i As Integer = 0 To view.Documents.IndexOf(view.ActiveDocument) - 1
            activationOrder.Add(view.Documents(i))
        Next i
        For Each item In view.FloatDocuments
            activationOrder.Add(item)
        Next item
    public Integer Compare(BaseDocument x, BaseDocument y)
        Dim xIndex As Integer = activationOrder.IndexOf(x)
        Dim yIndex As Integer = activationOrder.IndexOf(y)
        Return xIndex.CompareTo(yIndex)

See Also

UseDocumentSelector

Document Selector

IBaseDocumentSelectorProperties Interface

IBaseDocumentSelectorProperties Members

DevExpress.XtraBars.Docking2010.Customization Namespace