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
close icon

How to sort the Multi column tree view based on selected column index

Hi,

I want to sort the multi column tree view items based on column selection. Please suggest me how to do it.

The following is the code, which is sorting always with 0th column index. Hence i want sort based on column header selection (i.e. either 0,1,...).
if (treeNodesCollections[nodeIndex].HasNodes && treeNodesCollections[nodeIndex].Expanded)
{
      SortPatternExplorer(treeNodesCollections[nodeIndex], _treeViewSortOrder, _sortColumnIdx);
}

private void SortPatternExplorer(TreeNodeAdv treeNode, SortOrder order, int columnIdx)
{
            treeNode.SortOrder = order;
            treeNode.Sort();
}

In this above SortPatternExplorer taking sorting order but order applies based on 0th idex. instead of that i want to use the parameter "columnIdx".

Thanks & Regards
Gangadhar Yalaga

1 Reply

SK Senthil Kumaran Rajan Syncfusion Team February 17, 2016 11:36 AM UTC

Hi Gangadhar,

Thanks for contacting Syncfusion Support.

The reported requirement can be achieved by passing the Root Node of the MultiColumnTreeView and ColumnIndex into the SortNodeByColumn function, Please make use of the below code example.

Code Example [C#]:

//Pass the column index and root of the MultiColumnTreeView

SortNodesByColumn(this.multiColumnTreeView1.Root, 1);

//To Sort the MultiColumnTreeView based on the Column index

private void SortNodesByColumn(TreeNodeAdv ParentNode, int ColumnIndex)

{

            foreach (TreeNodeAdv node in ParentNode.Nodes)

            {

                        if (node.HasNodes)

                        {

                                    SortNodesByColumn(node, 1);

                        }

               node.Nodes.Sort(new SortBySubItems(this.multiColumnTreeView1, ColumnIndex, this.CheckBox1.Checked));

            }

}


We have prepared a sample and video for your reference and it can be downloaded from the below location.

Sample : http://www.syncfusion.com/downloads/support/forum/122103/MULTIC~1775032573.ZIP

Video : http://www.syncfusion.com/downloads/support/forum/122103/ze/MultiColumnSorting1678006044

Regards,
Senthil

Loader.
Live Chat Icon For mobile
Up arrow icon