This is a migrated thread and some comments may be shown as answers.

How to sort child nodes of a node.

1 Answer 426 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Kipp
Top achievements
Rank 1
Kipp asked on 24 Feb 2013, 03:50 PM
How can I sort the child nodes of a particular node?

1 Answer, 1 is accepted

Sort by
0
Accepted
Svett
Telerik team
answered on 27 Feb 2013, 02:16 PM
Hi Kipp,

Thank you for writing.

You can do that by using custom sorting and creating a custom node comparer. You can use the following code snippet:
public class TreeViewComparer : IComparer<RadTreeNode>
{
    public int Compare(RadTreeNode x, RadTreeNode y)
    {
        if (x.Parent != null && x.Parent == y.Parent && x.Parent.Name == "YourNode")
        {
            return Comparer<string>.Default.Compare(x.Name, y.Name);
        }
 
        return 0;
    }
}

this.radTreeView1.TreeViewElement.SortOrder = SortOrder.Ascending;
this.radTreeView1.TreeViewElement.Comparer = new TreeViewComparer();

I hope this helps.

Kind regards,
Svett
the Telerik team
Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Tags
Treeview
Asked by
Kipp
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or