ExpandAllHierarchyItems() doesn't work

7 posts, 0 answers
  1. Bin
    Bin avatar
    9 posts
    Member since:
    Jun 2011

    Posted 12 Jan 2012 Link to this post

    Hi,

    I'm using 2011 Q1 version of RadTreeListView to show some hierarchical data. The data only have two layer: parent level category, under each category, there are some data errors:

    In xaml:
    ...

    <UserConrol.DataContext>

        <viewmodel:DataErrorsViewModel x:Name="Data" />

    </UserConrol.DataContext>

    ...

    <

    telerik:RadTreeListView x:Name="TreeListView" ItemsSource="{Binding DataErrors, Mode=TwoWay}" DataLoaded="TreeListView_DataLoaded">
    ...

    </telerik:RadTreeListView>


    In Code-Behind:
    ...
    private
    void TreeListView_DataLoaded(object sender, System.EventArgs e)  

    {

        TreeListView.DataLoaded -= TreeListView_DataLoaded;

        TreeListView.ExpandAllHierarchyItems();

    }

    The ItemsSource(DataErrors) is populated by a view model class. The above code only works when I populate some dummy data. But when I call a service method asynchronously to populate the ItemsSource, the above code doesn't work because when the event handler is called, the asynchronous call hasn't been finished yet so there is nothing in the ItemsSource.

    Is there any other way to do this? Please Help. 

  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 13 Jan 2012 Link to this post

    Hello,

    When the data is loaded asynchronously, you could expand each row on RadGridView's RowLoaded event, or alternatively, to invoke ExpandAllHierarchyItems after all the elements have been added to the visual tree.

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Bin
    Bin avatar
    9 posts
    Member since:
    Jun 2011

    Posted 13 Jan 2012 Link to this post

    Hi Didie,

    Thank you for your reply. Would you mind giving me some sample code?

    Thanks,
    Bin
  5. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 13 Jan 2012 Link to this post

    Hello,

     Actually, you can try setting the AutoExpandItems property of the RadTreeListView to True. That way the hierarchy items should be expanded once the data is loaded.

    <telerik:RadTreeListView AutoExpandItems="True"/>

    Does this do the trick?
     

    Kind regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. Bin
    Bin avatar
    9 posts
    Member since:
    Jun 2011

    Posted 13 Jan 2012 Link to this post

    Hi Didie,

    AutoExpendItems property is not available for me (The Property 'AutoExpandItems was not found in type 'RadTreeListView'.)

    I'm using Q1 2011 SP1 version of Rad Controls and I reference telerik in XAML by

    xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"

    Any idea?

     

  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 13 Jan 2012 Link to this post

    Hello,

     Then you could try to set the ItemsSource of the TreeListView in the completed event of the Service. Then call the ExpandAllHierarchyItems() method.

    Please let me know how this works.


    Regards,
    Didie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Bin
    Bin avatar
    9 posts
    Member since:
    Jun 2011

    Posted 13 Jan 2012 Link to this post

    Didie,

    It works but it's agaisnt the MVVM principle. I have to reference the view within the view model and set the UI behavior in the view model.

    For now it's good enough. I just wish I could do it in XAML.

    Thanks for your help!
    Bin

Back to Top
DevCraft banner