Expanding all RadTreeview Items

5 posts, 1 answers
  1. Srikrishna
    Srikrishna avatar
    18 posts
    Member since:
    Apr 2012

    Posted 29 Jun 2012 Link to this post


    Hi Telerik,

    I am using RadTreeview and adding Items into Treeview dynamically from the database.How can i expand all the TreeviewItems on page load?

    I tried on Item prepared event by using Treeview.Isexpanded = true; , but its not working. Treeview.IsExpanded is coming false when i viewed in debugging mode.

    Thanks in Advance.
  2. Lancelot
    Lancelot avatar
    251 posts
    Member since:
    Jul 2012

    Posted 03 Jul 2012 Link to this post

    Hi Srikrishna,

    You are properly using the ItemPrepared event, but instead of TreeView.IsExpanded just call ExpandAll() 

    Here is the documentation that explains a little further about ExpandAll() and collapseAll().

    Good Luck
    Lancelot
  3. DevCraft banner
  4. Srikrishna
    Srikrishna avatar
    18 posts
    Member since:
    Apr 2012

    Posted 03 Jul 2012 Link to this post


    Hi Lancelot,
    Thanks for the reply.
    I used ExpandAll() method in the loaded event of the Treeview but it didn't work. I am loading treeview items dynamically from the database tables. Is this the problem?
    private void TreeView_Role_Loaded(object sender, RoutedEventArgs e)
           {
               TreeView_Role.ExpandAll();
           }

  5. Answer
    Lancelot
    Lancelot avatar
    251 posts
    Member since:
    Jul 2012

    Posted 03 Jul 2012 Link to this post

    Your code looks perfect, so what you're probably experiencing is that the Treeview is not populated when you call for the ExpandAll method. You need to wait until you're sure the data is loaded, then call ExpandAll(). 

    I dont know how your data is set up, but either check for all the data first or use a thread sleep method. If you know it takes a second for your data to populate the TreeView, the delay the method by a second.

    Its not glamorous, but if your data needs the extra time to load then it will work. Just know that this is the order that you need to follow.

            1                        2                     3                  4
    Page loads> TreeView Loads > Load Data > Expand All

    #3 has to happen before you can use #4

    Good Luck,
    Lancelot
  6. Srikrishna
    Srikrishna avatar
    18 posts
    Member since:
    Apr 2012

    Posted 04 Jul 2012 Link to this post


    Thanks Lancelot. I got it resolved now.
Back to Top
DevCraft banner