Sorting rad TreeView after databinding

3 posts, 0 answers
  1. Johan
    Johan avatar
    617 posts
    Member since:
    Mar 2007

    Posted 03 Apr 2007 Link to this post

    Requirements

    r.a.d.controls version rad TreeView 6.x +
    .NET version

    1.x and 2.x     
    Visual Studio version

    VS 2005
    programming language

    C#
    browser support

    all browsers supported by r.a.d.controls


     
    PROJECT DESCRIPTION
    Demonstrates how to sort the treeview after databinding. Currently only swaps the Text of the nodes, you may need to modify the code to swap Value, Category, etc (all the properties you need).
  2. Tonino
    Tonino avatar
    107 posts
    Member since:
    Nov 2007

    Posted 01 Sep 2009 Link to this post

    Hello!

    I just downloaded the project and modified the data Default.aspx like this:
       <radT:RadTreeView ID="RadTreeView1" runat="server"
          <Nodes> 
             <radT:RadTreeNode runat="server" Text="item c"
                <Nodes> 
                   <radT:RadTreeNode runat="server" Text="c2"
                   </radT:RadTreeNode> 
                   <radT:RadTreeNode runat="server" Text="c1"
                      <Nodes> 
                         <radT:RadTreeNode runat="server" Text="c1_2"
                         </radT:RadTreeNode> 
                         <radT:RadTreeNode runat="server" Text="c1_3"
                         </radT:RadTreeNode> 
                         <radT:RadTreeNode runat="server" Text="c1_1"
                         </radT:RadTreeNode> 
                      </Nodes> 
                   </radT:RadTreeNode> 
                </Nodes> 
             </radT:RadTreeNode> 
             <radT:RadTreeNode runat="server" Text="item a"
                <Nodes> 
                   <radT:RadTreeNode runat="server" Text="a1"
                      <Nodes> 
                         <radT:RadTreeNode runat="server" Text="a1_1"
                         </radT:RadTreeNode> 
                      </Nodes> 
                   </radT:RadTreeNode> 
                </Nodes> 
             </radT:RadTreeNode> 
             <radT:RadTreeNode runat="server" Text="item b"
                <Nodes> 
                   <radT:RadTreeNode runat="server" Text="b2"
                   </radT:RadTreeNode> 
                   <radT:RadTreeNode runat="server" Text="b1"
                   </radT:RadTreeNode> 
                   <radT:RadTreeNode runat="server" Text="b3"
                      <Nodes> 
                         <radT:RadTreeNode runat="server" Text="b3_2"
                         </radT:RadTreeNode> 
                         <radT:RadTreeNode runat="server" Text="b3_1"
                         </radT:RadTreeNode> 
                      </Nodes> 
                   </radT:RadTreeNode> 
                </Nodes> 
             </radT:RadTreeNode> 
          </Nodes> 
       </radT:RadTreeView> 
     

    I was expecting to see the nodes starting with 'a' under 'item a' and the nodes starting with 'b' under 'item b'. But what I get is this:
    - item a 
    |   |_c1 
    |   |_c2 
    |     |_c1_1 
    |     |_c1_2 
    |     |_c1_3      
    - item b 
    |   |_a1 
    |     |_a1_1 
    - item c 
        |_b1 
        |_b2 
        |_b3 
          |_c3_1  
          |_c3_2 
     


    Is the sorting not working correctly or am I misunderstanding something?

    Thanks for helping,
    Tonino.





  3. StevenJ
    StevenJ avatar
    7 posts
    Member since:
    Sep 2005

    Posted 19 May 2011 Link to this post

    It's better with LINQ

    Create your nodes to a list collection List<radTreeNode>

    Sort the List, then add to the nodes using the AddRange method.

    Here's the sort in LINQ.

     

     

     

    protected List<RadTreeNode> SortNodeCollection(List<RadTreeNode> nodes)

     

     

    {

     

     

    List<RadTreeNode> returnCollection = new List<RadTreeNode>();

     

     

     

    var q = from node in nodes

     

     

     

    orderby node.Text ascending

     

     

     

     

     

     

     

    select node;

     

     

    returnCollection = q.ToList<

    RadTreeNode>();

     

     

     

    return returnCollection;

     

     

    }

Back to Top