Search code examples
.netdockpanel-suite

DockPanel Suite tab sorting


one of my projects uses WeiFen Luo's DockPanel Suite http://dockpanelsuite.com/. Now customer demands to have tabs sorted in a given order when in Document view.

The tabs are all instances of the same DockContent-derived class. It carries a float by which to sort.

DockPanel.Contents is a DockContentCollection that sadly doesn't provide a Sort method like other collections. It's also not possible to delete DockContents from it in order to add them in the correct order.

But user can drag a tab and drop it onto another to change their order.

Does anyone know how to do that "insert tab1 in tab2's place" programatically?

I know I should ask in a library-dependent forum, the "how to ask a question" entry there leads here.


Solution

  • If you dig into the sample project's MainForm.menuItemLayoutByCode_Click method, you can see how to control layout via C# code.

    doc1.Show(dockPanel, DockState.Document);
    doc2.Show(doc1.Pane, null);
    doc3.Show(doc1.Pane, null);
    doc4.Show(doc1.Pane, null);
    

    The effect of above code is that Document4 shows as the active tab, while the previous three are in order.

    So to move Document1 and Document2, you can use

    doc1.Show(dockPanel, DockState.Document);
    doc2.Show(doc1.Pane, null);
    doc3.Show(doc1.Pane, null);
    doc4.Show(doc1.Pane, null);
    doc1.Show(doc1.Pane, null);
    doc2.Show(doc1.Pane, null);
    

    Do you get it? It is simply a stack, and you can fully control the order.