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

Recursion selection problem with UI Virtualization

2 Answers 109 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mohamed Hussain Nabhan Hussain
Top achievements
Rank 1
Mohamed Hussain Nabhan Hussain asked on 09 May 2012, 03:55 PM
I have a RadTreeView that is using  hierarichal data template, and it is binded with thousands of records.
I am using UI Virtualization, to increase performance and the VirtualizationMode is standard.

In my case, i want to choose a group and highlight all children recursively, however it don't highlight all the children, and i guess this is due to the virtualization, as some of the children are not yet rendered.

This is my xaml tree code:

 

<my:RadTreeView Margin="2,2,2,0" IsLineEnabled="True" Name="RadtreeView1" IsVirtualizing="True" tree:TreeViewPanel.VirtualizationMode="Hierarchical" IsLoadOnDemandEnabled="True" TabIndex="1" telerik:TextSearch.TextPath="Fields.Name" IsDragDropEnabled="False" SelectionMode="Multiple" Background="White" KeyDown="RadtreeView1_KeyDown" Selected="RadtreeView1_Selected" ScrollViewer.VerticalScrollBarVisibility="Visible">
  
  
  
<telerik:RadContextMenu.ContextMenu >
  
  
  
<telerik:RadContextMenu x:Name="RadContext" Opened="RadContextMenu_Opened" >
  
  
  
<MenuItem Header="Select All Children" Click="MenuItem_Click"/>
  
  
  
</telerik:RadContextMenu>
  
  
  
</telerik:RadContextMenu.ContextMenu>
  
<my:RadTreeView.ItemTemplate>
  
  
  
<HierarchicalDataTemplate >
  
<StackPanel Orientation="Horizontal" >
  
  
  
<Image Source="{Binding Path=Fields.ImagePath}"></Image>
  
  
  
<TextBlock Text="{Binding Path=Fields.Code}" Foreground="{Binding Path=Fields.isGroup,Converter={StaticResource BoolFontConverter} }" Width="50"></TextBlock>
  
<TextBlock Text=" | " Foreground="{Binding Path=Fields.isGroup,Converter={StaticResource BoolFontConverter} }"></TextBlock>
  
<TextBlock Text="{Binding Path=Fields.Name}" Foreground="{Binding Path=Fields.isGroup,Converter={StaticResource BoolFontConverter} }" Width="200"></TextBlock>
  
<TextBlock Text=" | " Foreground="{Binding Path=Fields.isGroup,Converter={StaticResource BoolFontConverter} }"></TextBlock>
  
<TextBlock Text="{Binding Path=Fields.Alias}" Foreground="{Binding Path=Fields.isGroup,Converter={StaticResource BoolFontConverter}}" Width="200"></TextBlock>
  
</StackPanel>
 
</HierarchicalDataTemplate>
  
</my:RadTreeView.ItemTemplate>
  
  
  
</my:RadTreeView>
This is the C# Code of recursion selection :

 

 

foreach(RadTreeViewItem item in SelectedNode.ChildrenOfType<RadTreeViewItem>())
  
{
  
item.IsSelected = true;
  
}

 


Notes:
1-This code do not select all the children.
2-SelectedNode is of type RadTreeViewItem.


Thanks in advance

2 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 14 May 2012, 03:29 PM
Hi Mohamed,

It's not a good practice to use the ChildrenOfType method to traverse the items of a RadTreeViewItem. Instead you can traverse its Items collection. And as you're using data-binding approach, I'd suggest adding a two-way binding for the IsSelected property of the RadTreeViewItems.

This will allow you to control the selection only through business properties, and even if the parent RAdTreeViewItem is collapsed, you can change the selection of the items in its business collection of children and it will be applied as soon as the items are displayed on the screen.

I attached a sample solution to demonstrate this approach. Please keep in mind that the selection logic will only work on those RadTreeViewItems which Items collection is already populated through the LoadOnDemand mechanism.

Regards,
Tina Stancheva
the Telerik team

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

0
Bill
Top achievements
Rank 1
answered on 26 Apr 2013, 05:53 AM
Hi telerick:
    The style set the IsExpanded="True",but  I used UI Virtualization,so the IsExpanded not work. How can I do? thanks
Tags
TreeView
Asked by
Mohamed Hussain Nabhan Hussain
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Bill
Top achievements
Rank 1
Share this question
or