Back to Devexpress

Document Selector

windowsforms-11362-controls-and-libraries-application-ui-manager-views-document-selector.md

latest6.5 KB
Original Source

Document Selector

  • Oct 29, 2020
  • 3 minutes to read

The Document Selector dialog allows end-users to switch between Documents and dock panels by pressing the following hot-keys:

  • Ctrl + Tab - switch to the previous document (hold “Ctrl” and press “Tab” repeatedly to navigate to previously active documents);
  • Ctrl + Shift + Tab - cycle through documents forward (i.e. in the direction opposite to the Ctrl+Tab navigation);
  • Left and Right arrows - toggle between the Document and panel navigation.

This dialog is supported in all Views except the WindowsUI View. To turn the Document Selector off, disable the BaseView.UseDocumentSelector setting.

Related API

Item Order

The Document Selector tracks the sequence in which end-users activate Documents and panels, and arranges its items in the reverse order so that a user moves back to previous panels when holding “Ctrl” and repeatedly pressing “Tab”. The figure below illustrates the order in which the Document Manager’s Documents were activated and how the Document Selector arranges them.

To change this default order, set the IBaseDocumentSelectorProperties.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 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)