Hi,
I am using RadTreeView in my WPF application and binding it to an object. Which is working as expected.
Problem: Whenever I add new item in RadTreeView or edit any existing item, I reload my RadTreeView binding object. But I always end up with my either my root node as selected or child of root node. I want my new item (which I have added recently) or edited item to be selected. In my case I have a root node and it can have any number of child node, and those child nodes can have any number of child node. So I have 3 level hierarchy. But after I refresh my binding object (which is TreeViewDataSource in my case) I always end up with my second level and third level never expands.
My XAML code for RadTreeView is:
<Grid >
<Grid.Resources>
<!--Data template for the Sensor object-->
<HierarchicalDataTemplate x:Key="SensorTemplate">
<StackPanel Orientation="Horizontal">
<Image Source="/MORASS;component/Images/Sensor.png" />
<TextBlock Text="{Binding SensorName}" Margin="2" />
</StackPanel>
</HierarchicalDataTemplate>
<!--Data template for the Logger object-->
<!--<Image Source="/MORASS;component/Images/Logger.png">-->
<HierarchicalDataTemplate x:Key="LoggerTemplate"
ItemTemplate="{StaticResource SensorTemplate}"
ItemsSource="{Binding Sensor}">
<StackPanel Orientation="Horizontal">
<Image>
<Image.Style>
<Style TargetType="{x:Type Image}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsManualType}" Value="false">
<Setter Property="Source" Value="/MORASS;component/Images/Logger.png"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsManualType}" Value="true">
<Setter Property="Source" Value="/MORASS;component/Images/Logger-Manual.png"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
<TextBlock Text="{Binding LoggerDescription}" Margin="2" />
</StackPanel>
</HierarchicalDataTemplate>
<!--Data template for the Location object-->
<HierarchicalDataTemplate
x:Key="LocationTemplate"
ItemsSource="{Binding Logger}"
ItemTemplate="{StaticResource LoggerTemplate}">
<StackPanel Orientation="Horizontal">
<Image Source="/MORASS;component/Images/Location.png" />
<TextBlock Text="{Binding LocationName}" Margin="2" />
</StackPanel>
</HierarchicalDataTemplate>
</Grid.Resources>
<telerik:RadTreeView Name="radTreeViewMain" SelectedItem="{Binding SelectedItemNode}" IsLineEnabled="True" SelectedValuePath="{Binding Type}" SelectionChanged="radTreeViewMain_SelectionChanged" >
<telerik:RadTreeViewItem Header="Locations" IsExpanded="True" ContextMenu="{Binding Source={StaticResource TreeContextMenu}}" ItemsSource="{Binding TreeViewDataSource}" ItemTemplate="{StaticResource LocationTemplate}">
</telerik:RadTreeViewItem>
</telerik:RadTreeView>
</Grid>
Any help will be highly appreciated.
Regards,
Moon
I am using RadTreeView in my WPF application and binding it to an object. Which is working as expected.
Problem: Whenever I add new item in RadTreeView or edit any existing item, I reload my RadTreeView binding object. But I always end up with my either my root node as selected or child of root node. I want my new item (which I have added recently) or edited item to be selected. In my case I have a root node and it can have any number of child node, and those child nodes can have any number of child node. So I have 3 level hierarchy. But after I refresh my binding object (which is TreeViewDataSource in my case) I always end up with my second level and third level never expands.
My XAML code for RadTreeView is:
<Grid >
<Grid.Resources>
<!--Data template for the Sensor object-->
<HierarchicalDataTemplate x:Key="SensorTemplate">
<StackPanel Orientation="Horizontal">
<Image Source="/MORASS;component/Images/Sensor.png" />
<TextBlock Text="{Binding SensorName}" Margin="2" />
</StackPanel>
</HierarchicalDataTemplate>
<!--Data template for the Logger object-->
<!--<Image Source="/MORASS;component/Images/Logger.png">-->
<HierarchicalDataTemplate x:Key="LoggerTemplate"
ItemTemplate="{StaticResource SensorTemplate}"
ItemsSource="{Binding Sensor}">
<StackPanel Orientation="Horizontal">
<Image>
<Image.Style>
<Style TargetType="{x:Type Image}">
<Style.Triggers>
<DataTrigger Binding="{Binding IsManualType}" Value="false">
<Setter Property="Source" Value="/MORASS;component/Images/Logger.png"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsManualType}" Value="true">
<Setter Property="Source" Value="/MORASS;component/Images/Logger-Manual.png"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Image.Style>
</Image>
<TextBlock Text="{Binding LoggerDescription}" Margin="2" />
</StackPanel>
</HierarchicalDataTemplate>
<!--Data template for the Location object-->
<HierarchicalDataTemplate
x:Key="LocationTemplate"
ItemsSource="{Binding Logger}"
ItemTemplate="{StaticResource LoggerTemplate}">
<StackPanel Orientation="Horizontal">
<Image Source="/MORASS;component/Images/Location.png" />
<TextBlock Text="{Binding LocationName}" Margin="2" />
</StackPanel>
</HierarchicalDataTemplate>
</Grid.Resources>
<telerik:RadTreeView Name="radTreeViewMain" SelectedItem="{Binding SelectedItemNode}" IsLineEnabled="True" SelectedValuePath="{Binding Type}" SelectionChanged="radTreeViewMain_SelectionChanged" >
<telerik:RadTreeViewItem Header="Locations" IsExpanded="True" ContextMenu="{Binding Source={StaticResource TreeContextMenu}}" ItemsSource="{Binding TreeViewDataSource}" ItemTemplate="{StaticResource LocationTemplate}">
</telerik:RadTreeViewItem>
</telerik:RadTreeView>
</Grid>
Any help will be highly appreciated.
Regards,
Moon