Hello,
I have a treeview that should display the contents of my self-referencing table in the database. This table contains a list of hierarchical status types. This table has primary key and parentID columns. I am using ADO.NET data services to get the data. I modeled the code similar to your on-demand example .
In the initial data query used to load the treeview item source, I used expand methods to get the child items of the root nodes and that works fine (I can navigate to the next level). If the user attempts to expand a child node, I get the item, convert it to the cooresponding object and then call the Context.BeginLoadProperty to load the related items for this entity. The relation used to populate the items is called "ChildCategories".
I can see in the async completed event that the current node's child relation has the correct number of child objects, but the treeview control displays a circular icon and does not display the child nodes. Does the tree view control need to be refreshed?
Almost there, but must be missing something. Please inspect the following.
Thanks in advance for your help.
Jeff
Here is the code behind
I have a treeview that should display the contents of my self-referencing table in the database. This table contains a list of hierarchical status types. This table has primary key and parentID columns. I am using ADO.NET data services to get the data. I modeled the code similar to your on-demand example .
In the initial data query used to load the treeview item source, I used expand methods to get the child items of the root nodes and that works fine (I can navigate to the next level). If the user attempts to expand a child node, I get the item, convert it to the cooresponding object and then call the Context.BeginLoadProperty to load the related items for this entity. The relation used to populate the items is called "ChildCategories".
I can see in the async completed event that the current node's child relation has the correct number of child objects, but the treeview control displays a circular icon and does not display the child nodes. Does the tree view control need to be refreshed?
Almost there, but must be missing something. Please inspect the following.
Thanks in advance for your help.
Jeff
<telerik:RadPage x:Class="SilverlightClient.StatusTypeLookupPage" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:ms="clr-namespace:System.Windows.Controls;assembly=System.Windows" |
xmlns:toolkit="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls" |
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" |
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" |
xmlns:blacklight="clr-namespace:Blacklight.Silverlight.Controls;assembly=Blacklight.Silverlight.Controls" |
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls" |
xmlns:telerikDocking="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Docking" |
xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input" |
xmlns:telerikMedia="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.MediaPlayer" |
xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation" |
xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" |
xmlns:telerikGridView="clr-namespace:Telerik.Windows.Controls.GridView;assembly=Telerik.Windows.Controls.GridView" |
xmlns:xapWorksModel="clr-namespace:SilverlightClient.xapWorksEntities" |
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows" |
xmlns:local="clr-namespace:SilverlightClient" |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
Width="Auto" Height="Auto" mc:Ignorable="d" d:DesignWidth="1200" d:DesignHeight="800" Margin="0,0,0,0"> |
<telerik:RadPage.Resources> |
<DataTemplate x:Key="ItemTemplate"> |
<TextBlock Text="{Binding Description}" /> |
</DataTemplate> |
<telerik:HierarchicalDataTemplate |
x:Key="CategoryTemplate" |
ItemsSource="{Binding ChildCategories}" |
ItemTemplate="{StaticResource ItemTemplate}"> |
<TextBlock Text="{Binding Description}"/> |
</telerik:HierarchicalDataTemplate> |
</telerik:RadPage.Resources> |
<Grid x:Name="LayoutRoot" Background="{StaticResource PanelBackground3}" HorizontalAlignment="Stretch" Margin="0,25,0,0"> |
<Grid.RowDefinitions> |
<!-- the contact buttons goes here --> |
<RowDefinition Height="Auto"/> |
<!-- the main content goes here --> |
<RowDefinition Height="*"/> |
</Grid.RowDefinitions> |
<Grid.ColumnDefinitions> |
<ColumnDefinition Width="*" /> |
</Grid.ColumnDefinitions> |
<!-- create the page title --> |
<StackPanel Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Center"> |
<TextBlock Text="Status Type Category Manager" FontSize="30" Foreground="{StaticResource Wheat}"/> |
</StackPanel> |
<!-- create a stackpanel with 2 columns (one for the treeview containing the StatusTypeCategory(s), the other for the StatusTypes --> |
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" |
Grid.Row="1"> |
<!-- the first panel --> |
<StackPanel Orientation="Vertical" Width="400" VerticalAlignment="Stretch" Margin="20,20,20,20"> |
<TextBlock Text="Status Type Categories" FontSize="16" Foreground="#FFFFFFFF" /> |
<telerikNavigation:RadTreeView x:Name="RadTreeView1" Margin="0,30,0,0" |
Background="WhiteSmoke" |
MinHeight="500" |
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" |
IsOptionElementsEnabled="true" |
IsTriStateMode="true" IsLineEnabled="True" SelectionMode="Extended" |
IsEditable="True" |
IsLoadOnDemandEnabled="True" |
LoadOnDemand="RadTreeView1_LoadOnDemand" |
IsDragDropEnabled="True" ItemsOptionListType="CheckList" |
ImagesBaseDir="/Examples/Common/Images/VistaIcons/" |
ItemTemplate="{StaticResource CategoryTemplate}" |
Loaded="RadTreeView1_Loaded" /> |
<!-- define some buttons for CRUD operations --> |
<StackPanel Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Center" Margin="0,20,0,10"> |
<Button x:Name="NewCategoryButton" Height="Auto" Width="50" Margin="5,0,0,0" > |
<ContentPresenter> |
<StackPanel Orientation="Vertical"> |
<Image Source="../Images/VistaCommon/new_document_lined_24.png" Height="24"/> |
<TextBlock Text="New"/> |
</StackPanel> |
</ContentPresenter> |
</Button> |
<Button x:Name="AddCategoryButton" Height="Auto" Width="50" Margin="5,0,0,0" > |
<ContentPresenter> |
<StackPanel Orientation="Vertical"> |
<Image Source="../Images/VistaCommon/new_document_lined_24.png" Height="24"/> |
<TextBlock Text="Add"/> |
</StackPanel> |
</ContentPresenter> |
</Button> |
<Button x:Name="AddSubCategoryButton" Height="Auto" Width="50" Margin="5,0,0,0" > |
<ContentPresenter> |
<StackPanel Orientation="Vertical"> |
<Image Source="../Images/VistaCommon/new_document_lined_24.png" Height="24"/> |
<TextBlock Text="Sub"/> |
</StackPanel> |
</ContentPresenter> |
</Button> |
<Button x:Name="EditCategoryButton" Height="Auto" Width="50" Margin="5,0,0,0" > |
<ContentPresenter> |
<StackPanel Orientation="Vertical"> |
<Image Source="../Images/VistaCoreI/edit_24.png" Height="24"/> |
<TextBlock Text="Edit"/> |
</StackPanel> |
</ContentPresenter> |
</Button> |
<Button x:Name="SaveCategoryButton" Height="Auto" Width="50" Margin="5,0,0,0" > |
<ContentPresenter> |
<StackPanel Orientation="Vertical"> |
<Image Source="../Images/VistaCommon/save_24.png" Height="24"/> |
<TextBlock Text="Save"/> |
</StackPanel> |
</ContentPresenter> |
</Button> |
<Button x:Name="DeleteCategoryButton" Height="Auto" Width="50" Margin="5,0,0,0" > |
<ContentPresenter> |
<StackPanel Orientation="Vertical"> |
<Image Source="../Images/VistaCommon/delete_24.png" Height="24"/> |
<TextBlock Text="Delete"/> |
</StackPanel> |
</ContentPresenter> |
</Button> |
</StackPanel> |
</StackPanel> |
<!-- the second panel --> |
<StackPanel Orientation="Vertical" Width="400" Margin="60,20,20,20"> |
<TextBlock Text="Status Types" FontSize="16" Foreground="#FFFFFFFF"/> |
<!-- this is the status type grid --> |
<telerikGrid:RadGridView x:Name="StatusTypeGrid" Grid.Row="1" MinHeight="500" Margin="0,30,0,0" |
AutoGenerateColumns="False" |
ShowGroupPanel="False" > |
<telerikGrid:RadGridView.Columns> |
<telerikGridView:GridViewDataColumn |
HeaderText="Status Type" |
UniqueName="Description" |
Width="400"/> |
</telerikGrid:RadGridView.Columns> |
</telerikGrid:RadGridView> |
<!-- define some buttons for CRUD operations --> |
<StackPanel Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Center" Margin="0,20,0,10"> |
<Button x:Name="NewStatusTypeButton" Height="Auto" Width="50" Margin="5,0,0,0" > |
<ContentPresenter> |
<StackPanel Orientation="Vertical"> |
<Image Source="../Images/VistaCommon/new_document_lined_24.png" Height="24"/> |
<TextBlock Text="New"/> |
</StackPanel> |
</ContentPresenter> |
</Button> |
<Button x:Name="EditStatusTypeButton" Height="Auto" Width="50" Margin="5,0,0,0" > |
<ContentPresenter> |
<StackPanel Orientation="Vertical"> |
<Image Source="../Images/VistaCoreI/edit_24.png" Height="24"/> |
<TextBlock Text="Edit"/> |
</StackPanel> |
</ContentPresenter> |
</Button> |
<Button x:Name="SaveStatusTypeButton" Height="Auto" Width="50" Margin="5,0,0,0" > |
<ContentPresenter> |
<StackPanel Orientation="Vertical"> |
<Image Source="../Images/VistaCommon/save_24.png" Height="24"/> |
<TextBlock Text="Save"/> |
</StackPanel> |
</ContentPresenter> |
</Button> |
<Button x:Name="DeleteStatusTypeButton" Height="Auto" Width="50" Margin="5,0,0,0" > |
<ContentPresenter> |
<StackPanel Orientation="Vertical"> |
<Image Source="../Images/VistaCommon/delete_24.png" Height="24"/> |
<TextBlock Text="Delete"/> |
</StackPanel> |
</ContentPresenter> |
</Button> |
</StackPanel> |
</StackPanel> |
</StackPanel> |
</Grid> |
</telerik:RadPage> |
Here is the code behind
Imports System |
Imports System.ComponentModel |
Imports System.Collections.Generic |
Imports System.Collections.ObjectModel |
Imports System.Linq |
Imports System.Net |
Imports System.Windows |
Imports System.Windows.Controls |
Imports System.Windows.Data |
Imports System.Windows.Documents |
Imports System.Windows.Input |
Imports System.Windows.Media |
Imports System.Windows.Media.Animation |
Imports System.Windows.Shapes |
Imports Blacklight |
Imports Telerik.Windows |
Imports Telerik.Windows.Controls |
Imports Telerik.Windows.Controls.Docking |
Imports Telerik.Windows.Controls.GridView |
Imports Telerik.Windows.Controls.GridView.Rows |
Imports Telerik.Windows.Input |
Imports Telerik.Windows.Controls.MediaPlayer |
Imports Telerik.Windows.Controls.Navigation |
Imports System.Data.Services.Client |
Imports SilverlightClient.xapWorksEntities |
Partial Public Class StatusTypeLookupPage |
Inherits Telerik.Windows.Controls.RadPage |
#Region "Variable Declarations" |
' create a collection to hold the StatusTypeCategory items |
Dim theStatusTypeCategories As New ObservableCollection(Of StatusTypeCategory) |
' create a collection to hold the child StatusTypeCategory items |
' we will dynamically load the children when a StatusTypeCategory node is selected |
Dim theStatusTypeCategoryChildren As New ObservableCollection(Of StatusTypeCategory) |
' create a variable to hold the current treeviewitem |
Dim theTreeViewItem As RadTreeViewItem |
' create a variable to thold the current StatusTypeCategory |
Dim theCategory As StatusTypeCategory |
#End Region |
Public Sub New() |
InitializeComponent() |
End Sub |
Private Sub RadTreeView1_Loaded(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) |
RadTreeView1.ItemsSource = App.theStatusTypeCategoryCollection |
End Sub |
Private Sub RadTreeView1_LoadOnDemand(ByVal sender As System.Object, ByVal e As Telerik.Windows.RadRoutedEventArgs) |
theTreeViewItem = TryCast(e.OriginalSource, RadTreeViewItem) |
theCategory = TryCast(theTreeViewItem.Item, StatusTypeCategory) |
If theCategory IsNot Nothing Then |
' get the child category's asyncronously |
LoadStatusTypeCategoryChildData(theCategory) |
Else |
theTreeViewItem.IsLoadOnDemandEnabled = False |
End If |
End Sub |
Private Sub LoadStatusTypeCategoryChildData(ByVal theCategory As StatusTypeCategory) |
App.theService.BeginLoadProperty(theCategory, _ |
"ChildCategories", _ |
New AsyncCallback(AddressOf LoadRelatedChildItemsComplete), _ |
theCategory) |
End Sub |
Private Sub LoadRelatedChildItemsComplete(ByVal result As IAsyncResult) |
App.theService.EndLoadProperty(result) |
If theCategory.ChildCategories.Count.Equals(0) Then |
' if we have no items, then set the control indicator |
theTreeViewItem.IsLoadOnDemandEnabled = False |
' refresh the treeview control |
End If |
End Sub |
Private Sub RadTreeView1_ItemPrepared(ByVal sender As System.Object, ByVal e As Telerik.Windows.Controls.RadTreeViewItemPreparedEventArgs) |
End Sub |
End Class |