loading selfreferencing data into TreeListView

2 posts, 0 answers
  1. Chris
    Chris avatar
    1 posts
    Member since:
    Nov 2009

    Posted 29 Jul 2011 Link to this post

    I want to display selfreferencing Data (ContentID > ParentContentID) in a TreeListView. I am using EF4 and I am binding a DataSource to the ItemsSource of the TLV. So far I select the items by selecting the root items (ParentContentID=null) and including the children. This way I only get the first level of children. How can I

    a) select the whole structure at once / with one qurey
    b) load the next level of nodes after expanding a parent node?

    Best regards,

        ItemTemplate="{StaticResource ItemTemplate}"
        ItemsSource="{Binding ElementName=contentDomainDataSource,Path=Data}"
        <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children}" />
        <telerik:GridViewDataColumn DataMemberBinding="{Binding Title}"
        <telerik:GridViewDataColumn DataMemberBinding="{Binding LastChange}"
        d:DesignData="{d:DesignInstance my:Content, CreateList=true}"
        <my:DscSketch />
            Value="{Binding ElementName=projectsDomainDataSource, Path=Data.CurrentItem.ProjectID}" />
            Value="-1" />

      public IQueryable<Content> GetContentByProjectID_ParentID(int projectID, int parentContentID)
        return this.ObjectContext.Contents.Include("Children").Where(c => c.ProjectID == projectID && c.ParentContentID== null).OrderByDescending(c=>c.ContentID);
    //This is the data Class to be displayed as a selfreferencing hierarchy:
      public partial class Content
          internal sealed class ContentMetadata
              // Metadata classes are not meant to be instantiated.
              private ContentMetadata()
              public Content Children { get; set; }
              public int ContentID { get; set; }
              public ContentType ContentType { get; set; }
              public Nullable<int> ContentTypeID { get; set; }
              public byte[] Doc { get; set; }
              public EntityCollection<Ink> Inks { get; set; }
              public Nullable<DateTime> LastChange { get; set; }
              public Nullable<int> ParentContentID { get; set; }
              public Project Project { get; set; }
              public Nullable<int> ProjectID { get; set; }
              public byte[] Thumb { get; set; }
              public string Title { get; set; }

  2. Dimitrina
    Dimitrina avatar
    3769 posts

    Posted 04 Aug 2011 Link to this post

    Hi Chris,

     As I understand you would like to select the whole data with one query. For that purpose you may get the data initially and then manage it using an appropriate ViewModel corresponding to your TreeListView.
    Then you bind the "Items"(for example) property of the ViewModel to be the ItemsSource of the TreeListView.
    For example in an "Items" property you select the data in the collection where  (c.ProjectID == projectID && c.ParentContentID==null).OrderByDescending(c=>c.ContentID); 

    That way the child data will be loaded to the TreeListView once the item has been expanded.

    Does this make sense in your case? Please let me know in case you need any further assistance.

    Best wishes,
    the Telerik team

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

Back to Top