2011 Q1 Custom Sorting

5 posts, 0 answers
  1. Marc
    Marc avatar
    8 posts
    Member since:
    Jun 2009

    Posted 10 Jun 2011 Link to this post

    Dear,

    I would like to customize sorting with the treeview.

    For instance I bound treeview to Person class entity list.

    Then I would like to sort by firstname or lastname or age.

    I tried SortDescriptors without success.

    Thanks

    Marc
  2. Marc
    Marc avatar
    8 posts
    Member since:
    Jun 2009

    Posted 14 Jun 2011 Link to this post

    Dear all,

    Nobody has a solution ?

    I tested and it's working with previous version of TELERIK.

    Thanks in advance

    Marc
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 16 Jun 2011 Link to this post

    Hello Marc,

    Thank you for contacting us.

    Currently, the RadTreeView contol does not support such functionality. The custom sorting and sorting using different properties of a bound object will be ready for our next release Q2 2011, planed for next month.

    Let me know if you have further questions.

    Best wishes,
    Julian Benkov
    the Telerik team
    Q1’11 SP1 of RadControls for WinForms is available for download; also available is the Q2'11 Roadmap for Telerik Windows Forms controls.
  5. Stephen McDaniel
    Stephen McDaniel avatar
    35 posts
    Member since:
    Mar 2008

    Posted 15 Dec 2011 Link to this post

    Has this been implemented yet?  I just tried updating to Q3 2011 and I'm also having problems doing custom sorting like this.
  6. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 20 Dec 2011 Link to this post

    Hi Stephen,

    The custom sorting and filtering operation for RadTreeView control is available in Q3 2011 SP1 which we have just released. In this version you can write a custom comparer:

    public SortedTreeView()
    {
        InitializeComponent();
     
        for (int i = 0; i < 100; i++)
        {
     
            RadTreeNode radTreeNode = new RadTreeNode(i.ToString());
     
            radTreeView1.Nodes.Add(radTreeNode);
        }
        for (int i = 0; i < 100; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                RadTreeNode radTreeNode = new RadTreeNode(i.ToString() + "-" + j.ToString());
                radTreeView1.Nodes[i].Nodes.Add(radTreeNode);
            }
     
        }
     
        radTreeView1.TreeViewElement.Comparer = new MyComparer(this.radTreeView1.TreeViewElement);
    }
     
    private bool FilterNode(RadTreeNode node)
    {
        if (node.Text.Length > 1)
        {
            return true;
        }
     
        return false;
    }
     
    private void radButton1_Click(object sender, EventArgs e)
    {
        //radTreeView1.SelectedNode.Remove();
        this.radTreeView1.Filter = "Custom";
     
         if (radTreeView1.SortOrder == SortOrder.None)
         {
             radTreeView1.SortOrder = SortOrder.Ascending;
         }
         else if (radTreeView1.SortOrder == SortOrder.Ascending)
         {
             radTreeView1.SortOrder = SortOrder.Descending;
         }
         else
         {
             radTreeView1.SortOrder = SortOrder.None;
         }
    }
     
    class MyComparer : TreeNodeComparer
    {
        public MyComparer(RadTreeViewElement treeView)
            :base(treeView)
        {
     
        }
     
        public override int Compare(RadTreeNode x, RadTreeNode y)
        {
            if (this.TreeViewElement.SortOrder == SortOrder.Descending)
            {
                return x.Text.CompareTo(y.Text);
            }
     
            return x.Text.CompareTo(y.Text) * -1;
        }
    }

    I hope this helps.

    Regards,
    Julian Benkov
    the Telerik team

    Q3’11
    of RadControls for WinForms is available for download (see what's new). Get it today.
Back to Top
UI for WinForms is Visual Studio 2017 Ready