Recursion selection problem with UI Virtualization

3 posts, 0 answers
  1. Mohamed Hussain Nabhan Hussain
    Mohamed Hussain Nabhan Hussain avatar
    17 posts
    Member since:
    Feb 2012

    Posted 09 May 2012 Link to this post

    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"/>
    <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>
    This is the C# Code of recursion selection :



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


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

    Thanks in advance
  2. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 14 May 2012 Link to this post

    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.

    Tina Stancheva
    the Telerik team

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

  3. Bill
    Bill avatar
    8 posts
    Member since:
    Dec 2012

    Posted 26 Apr 2013 Link to this post

    Hi telerick:
        The style set the IsExpanded="True",but  I used UI Virtualization,so the IsExpanded not work. How can I do? thanks
Back to Top