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

Expand specific rows on load

5 Answers 299 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 03 Mar 2012, 06:39 PM
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

5 Answers, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 07 Mar 2012, 01:50 PM
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 >>
0
Jake
Top achievements
Rank 1
answered on 07 Aug 2012, 05:52 PM
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();
}
0
Vlad
Telerik team
answered on 08 Aug 2012, 05:46 AM
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.

0
Jake
Top achievements
Rank 1
answered on 08 Aug 2012, 09:32 PM
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 
0
Jake
Top achievements
Rank 1
answered on 09 Aug 2012, 03:46 PM
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;
                }));


} 
Tags
TreeListView
Asked by
David
Top achievements
Rank 1
Answers by
Nick
Telerik team
Jake
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or