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

2011 Q1 Custom Sorting

4 Answers 147 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Marc
Top achievements
Rank 1
Marc asked on 10 Jun 2011, 03:01 PM
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

4 Answers, 1 is accepted

Sort by
0
Marc
Top achievements
Rank 1
answered on 14 Jun 2011, 02:00 PM
Dear all,

Nobody has a solution ?

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

Thanks in advance

Marc
0
Julian Benkov
Telerik team
answered on 16 Jun 2011, 08:24 AM
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.
0
Stephen McDaniel
Top achievements
Rank 1
answered on 16 Dec 2011, 02:27 AM
Has this been implemented yet?  I just tried updating to Q3 2011 and I'm also having problems doing custom sorting like this.
0
Julian Benkov
Telerik team
answered on 20 Dec 2011, 04:48 PM
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.
Tags
Treeview
Asked by
Marc
Top achievements
Rank 1
Answers by
Marc
Top achievements
Rank 1
Julian Benkov
Telerik team
Stephen McDaniel
Top achievements
Rank 1
Share this question
or