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

loading selfreferencing data into TreeListView

1 Answer 75 Views
TreeListView
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 29 Jul 2011, 12:07 PM
Hi,
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,
chris



  <telerik:RadTreeListView
    Margin="5,5,5,33"
    AutoGenerateColumns="False"
    HierarchyColumnIndex="0"
    Name="RtlvMain"
    ItemTemplate="{StaticResource ItemTemplate}"
    ItemsSource="{Binding ElementName=contentDomainDataSource,Path=Data}"
  >
  <telerik:RadTreeListView.ChildTableDefinitions>
    <telerik:TreeListViewTableDefinition ItemsSource="{Binding Children}" />
  </telerik:RadTreeListView.ChildTableDefinitions>
  <telerik:RadTreeListView.Columns>
    <telerik:GridViewDataColumn DataMemberBinding="{Binding Title}"
      Header="Title"
      Width="120"/>
    <telerik:GridViewDataColumn DataMemberBinding="{Binding LastChange}"
      Header="Date"
      Width="80"/>
    </telerik:RadTreeListView.Columns>
  </telerik:RadTreeListView>
 
 
...
 
 
  <riaControls:DomainDataSource
    Name="contentDomainDataSource"
    AutoLoad="True"
    d:DesignData="{d:DesignInstance my:Content, CreateList=true}"
    Height="0"
    LoadedData="ContentDomainDataSource_LoadedData"
    QueryName="GetContentByProjectID_ParentID"
    Width="0">
  <riaControls:DomainDataSource.DomainContext>
    <my:DscSketch />
  </riaControls:DomainDataSource.DomainContext>
    <riaControls:DomainDataSource.QueryParameters>
      <riaControls:Parameter
        ParameterName="projectID"
        Value="{Binding ElementName=projectsDomainDataSource, Path=Data.CurrentItem.ProjectID}" />
      <riaControls:Parameter
        ParameterName="parentContentID"
        Value="-1" />
    </riaControls:DomainDataSource.QueryParameters>
  </riaControls:DomainDataSource>


  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()
          {
          }
          [Include]
          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; }
      }
  }




1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 04 Aug 2011, 07:51 AM
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,
Didie
the Telerik team

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

Tags
TreeListView
Asked by
Chris
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or