How to sort child nodes of a node.

2 posts, 1 answers
  1. Kipp
    Kipp avatar
    23 posts
    Member since:
    Sep 2012

    Posted 24 Feb 2013 Link to this post

    How can I sort the child nodes of a particular node?
  2. Answer
    Svett avatar
    728 posts

    Posted 27 Feb 2013 Link to this post

    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,
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
Back to Top