Hello!
There are the following types of data:
namespace TelerikHierarchyChildTemplate.Model{ public class WatchList { public int WatchListId { get; set; } public string Moniker { get; set; } public ICollection<ContentWatchList> Content { get; set; } } public class ContentWatchList { public int ContentWatchListId { get; set; } public WatchList ParentWatchList { get; set; } public Item ItemItem { get; set; } } public class Item { public int ItemId { get; set; } public string Moniker { get; set; } public string Note { get; set; } public ICollection<ContentWatchList> ContentsWatchLists { get; set; } }}
There is a model (MainViewModel) that in the creation fills the collection. To be filled in correctly :)
using System;using System.Collections.Generic;using System.Collections.ObjectModel;using System.Linq;using Telerik.Windows.Controls;using TelerikHierarchyChildTemplate.Model;namespace TelerikHierarchyChildTemplate{ public class MainViewModel : ViewModelBase { private ObservableCollection<WatchList> _watchListsCollection; private ObservableCollection<ContentWatchList> _contentWatchListCollection; private ObservableCollection<Item> _itemsCollection; public ObservableCollection<WatchList> WatchListsCollection { get { return _watchListsCollection; } set { _watchListsCollection = value; OnPropertyChanged(()=> WatchListsCollection); } } public ObservableCollection<ContentWatchList> ContentWatchListCollection { get { return _contentWatchListCollection; } set { _contentWatchListCollection = value; OnPropertyChanged(()=>ContentWatchListCollection); } } public ObservableCollection<Item> ItemsCollection { get { return _itemsCollection; } set { _itemsCollection = value; OnPropertyChanged(()=> ItemsCollection); } } public MainViewModel() { WatchListsCollection = new ObservableCollection<WatchList> { new WatchList() { WatchListId = 0, Moniker = "List One", Content = new List<ContentWatchList>() }, new WatchList() { WatchListId = 1, Moniker = "List Two", Content = new List<ContentWatchList>() }, new WatchList() { WatchListId = 2, Moniker = "List Three", Content = new List<ContentWatchList>() } }; ItemsCollection = new ObservableCollection<Item> { new Item() { ItemId = 0, Moniker = "Item One", Note = "Note One", ContentsWatchLists = new List<ContentWatchList>() }, new Item() { ItemId = 1, Moniker = "Item Two", Note = "Note Two", ContentsWatchLists = new List<ContentWatchList>() }, new Item() { ItemId = 2, Moniker = "Item Three", Note = "Note Tree", ContentsWatchLists = new List<ContentWatchList>() }, new Item() { ItemId = 3, Moniker = "Item Four", Note = "Note Four", ContentsWatchLists = new List<ContentWatchList>() } }; ContentWatchListCollection = new ObservableCollection<ContentWatchList> { new ContentWatchList() { ContentWatchListId = 0, ParentWatchList = WatchListsCollection.First(p=>p.WatchListId==0), ItemItem = ItemsCollection.First(p=>p.ItemId==0) }, new ContentWatchList() { ContentWatchListId = 1, ParentWatchList = WatchListsCollection.First(p=>p.WatchListId==0), ItemItem = ItemsCollection.First(p=>p.ItemId==1) }, new ContentWatchList() { ContentWatchListId = 2, ParentWatchList = WatchListsCollection.First(p=>p.WatchListId==0), ItemItem = ItemsCollection.First(p=>p.ItemId==2) }, new ContentWatchList() { ContentWatchListId = 3, ParentWatchList = WatchListsCollection.First(p=>p.WatchListId==1), ItemItem = ItemsCollection.First(p=>p.ItemId==3) }, new ContentWatchList() { ContentWatchListId = 4, ParentWatchList = WatchListsCollection.First(p=>p.WatchListId==1), ItemItem = ItemsCollection.First(p=>p.ItemId==2) }, new ContentWatchList() { ContentWatchListId = 5, ParentWatchList = WatchListsCollection.First(p=>p.WatchListId==1), ItemItem = ItemsCollection.First(p=>p.ItemId==1) } }; foreach (var item in ItemsCollection) { foreach (var content in ContentWatchListCollection) { if (item.ItemId == content.ItemItem.ItemId) item.ContentsWatchLists.Add(content); } } foreach (var wachlist in WatchListsCollection) { foreach (var content in ContentWatchListCollection) { if (wachlist.WatchListId == content.ParentWatchList.WatchListId) wachlist.Content.Add(content); } } } }}
There is a view:
<Window x:Class="TelerikHierarchyChildTemplate.MainWindow" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid Grid.Row="0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <telerik:RadGridView Grid.Column="0" ItemsSource="{Binding WatchListsCollection}"></telerik:RadGridView> <telerik:RadGridView Grid.Column="1" ItemsSource="{Binding ContentWatchListCollection}"></telerik:RadGridView> <telerik:RadGridView Grid.Column="2" ItemsSource="{Binding ItemsCollection}"></telerik:RadGridView> </Grid> <Grid Grid.Row="1"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <telerik:RadGridView ItemsSource="{Binding WatchListsCollection}"> <telerik:RadGridView.ChildTableDefinitions> <telerik:GridViewTableDefinition> <telerik:GridViewTableDefinition.Relation> <telerik:PropertyRelation ParentPropertyName="Content" /> </telerik:GridViewTableDefinition.Relation> </telerik:GridViewTableDefinition> </telerik:RadGridView.ChildTableDefinitions> </telerik:RadGridView> <telerik:RadGridView Grid.Column="1" ItemsSource="{Binding WatchListsCollection}"> <telerik:RadGridView.ChildTableDefinitions> <telerik:GridViewTableDefinition/> </telerik:RadGridView.ChildTableDefinitions> <telerik:RadGridView.HierarchyChildTemplate> <DataTemplate> <telerik:RadGridView x:Name="RadGridView1" GroupRenderMode="Flat" DataContext="{Binding}" BorderThickness="0,1,0,1" GridLinesVisibility="None" CanUserFreezeColumns="False" AutoGenerateColumns="False" ItemsSource="{Binding ContentWatchListCollection}" ShowGroupPanel="False" IsReadOnly="True"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn DataMemberBinding="{Binding ItemItem.Moniker}" Header="Moniker" /> <telerik:GridViewDataColumn DataMemberBinding="{Binding ItemItem.Note}" Header="Note" /> </telerik:RadGridView.Columns> </telerik:RadGridView> </DataTemplate> </telerik:RadGridView.HierarchyChildTemplate> </telerik:RadGridView> </Grid> </Grid></Window>
Results of work on the attached image.
A hierarchical structure is displayed when using GridViewTableDefinition.Relation, and when using HierarchyChildTemplate, there is no.
I ask you to inform me that it is necessary to correct that the nested data began to be displayed at usage HierarchyChildTemplate
