Expand specific rows on load

6 posts, 0 answers
  1. David
    David avatar
    12 posts
    Member since:
    Mar 2009

    Posted 03 Mar 2012 Link to this post

    I am using a RadTreeListView and I want to have certain nodes (based on object type) expanded the first time they are loaded. I have tried several ways to do this but they all seem to have issues. I think most of the issues have to do with the fact that the row is not actually created or loaded at the time I try to expand it. I found the example used to expand all rows and that works but my tree is way to big to do that all the time.

    My current approach is to handle the RowLoaded event and if the e.DataElement meets the criteria call TreeListView.ExpandHierarchyItem(e.DataElement). This actually works except the TreeListView is initially blank (except with a scrollbar on the bottom). If I click the scoll bar the tree shows up (and the scroll bar goes away). The other issue with this is that if one of the expanded nodes is a child of a node that is not expanded the whole tree disappears never to return.

    Here is my RowLoaded event handler (not terribly complicated).

            private void TreeView_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
            {
                if ((e.DataElement != null) && (e.Row is GridViewRow) && !(e.Row is GridViewNewRow))
                {
                    if (e.DataElement is myObjectType)
                    {
                        this.TreeView.ExpandHierarchyItem(e.DataElement);
                    }
                }
            }

    Is there a better way to do this?

    Thanks
    Dave Goughnour

  2. Nick
    Admin
    Nick avatar
    593 posts

    Posted 07 Mar 2012 Link to this post

    Hello David,

    Another approach would be to set IsExpanded to the row itself. this can be implemented in the RowLoaded event by setting (e.Row as TreeeListViewRow).IsExpanded = true. 

    As for the blank TreeList, you can try to get the GridViewScrollViewer, using the ChildrenOfType method in Telerik.Windows.Controls, and invoke it's InvalidateMeasure. Could you try and see if this works for you? 

    Hope this helps! If you have any further questions, please don't hesitate to ask! 

    All the best,
    Nik
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Jake
    Jake avatar
    5 posts
    Member since:
    Oct 2010

    Posted 07 Aug 2012 Link to this post

    I also used the RowLoaded event handler to expand the tree node & got the blank children rows as well. If I collapse & re-expand the parent node then the children would show up. I upgraded to version 2012.1 + SP1 but it didn't fix the issue. 

    Telerik support: can you confirm this bug and let us know when it will be fixed? 


     void testTree_RowLoaded(object sender, RowLoadedEventArgs e)
      {
    var row = e.Row as TreeListViewRow;
    if ( row == null )
    return;

                    row.IsCurrent = true;
                    row.IsExpanded = true;

                    var scrollViewer = testTree.ChildrenOfType<GridViewScrollViewer>().FirstOrDefault();
                    if (scrollViewer != null)
                        scrollViewer.InvalidateMeasure();
    }
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 08 Aug 2012 Link to this post

    Hi,

    Can you send us small example project demonstrating your scenario to check locally what's going on in your case? 

    Regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Jake
    Jake avatar
    5 posts
    Member since:
    Oct 2010

    Posted 08 Aug 2012 Link to this post

    Thanks for the quick response, Vlad. I just submitted ticket 574644 along with a test application for this bug

    http://www.telerik.com/account/support-tickets/view-ticket.aspx?threadid=574644 
  7. Jake
    Jake avatar
    5 posts
    Member since:
    Oct 2010

    Posted 09 Aug 2012 Link to this post

    Finally got it to work thanks to Vlad's suggestion. The solution is to use the Dispatcher to set the IsExpand property. This would give the tree enough time to redraw. See solution below.

    void testTree_RowLoaded(object sender, RowLoadedEventArgs e)
      {
    var row = e.Row as TreeListViewRow;
    if ( row == null )
    return;

    // Use Dispatcher to give tree more time to expand & redraw layout
                Dispatcher.BeginInvoke((Action)(() =>
                    {
                        row.IsCurrent = true;
                        row.IsSelected = true;
                        row.IsExpanded = true;
                    }));


    } 
Back to Top
UI for WPF is Visual Studio 2017 Ready