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

Expand All extremely slow - how to show busy?

1 Answer 470 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Bob asked on 08 May 2012, 09:37 PM
Hello,

I have a fairly simple tree, but it may contain thousands of items in 5 or 6 levels of depth.  The data collection is bound in MVVM and exists in the view model.  I created a context menu on right click that allows the user to Expand All for a single node, which could potentially open hundreds of child nodes.  When the expand command is executed, the collection is traversed and elements are changed to IsExpanded = true.

What I notice is that my view model command executes very quickly, but then the actual tree control spends quite a long time initializing the items and displaying the levels (can be 30 seconds or longer).  I guess I can live with the long wait, but how do I present and clear a busy indicator when control is lost to the Telerik threads?  Trying to set the busy indicator around the view model command only lasts for a second.

Are there other options for a faster or more visual response from the tree control?

The tree:
<HierarchicalDataTemplate x:Key="TreeObjectTemplate" ItemContainerStyle="{StaticResource containerStyle}" ItemsSource="{Binding ChildNodes}">
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="{Binding DisplayName}" />
    </StackPanel>
</HierarchicalDataTemplate>
 
        <telerik:RadTreeView Grid.Row="0" x:Name="tvTree" ItemTemplate="{StaticResource TreeObjectTemplate}"
                        Margin="0,8,0,4" VerticalAlignment="Top" Padding="0,2,0,10"
                        IsSingleExpandPath="False" IsLineEnabled="True" ExpanderStyle="{DynamicResource ExpanderStyle}"
                        SelectionMode="Single" IsEditable="False" IsDragDropEnabled="False" ItemContainerStyle="{StaticResource containerStyle}"
                        ItemsSource="{Binding tvTreeData}"
                        SelectedItem="{Binding tvSelectedItem, Mode=TwoWay}"
                        MouseRightButtonDown="treeView_MouseRightButtonDown">
            <telerik:RadContextMenu.ContextMenu>
                <telerik:RadContextMenu>
                    <telerik:RadMenuItem Header="Expand All Levels" Command="{Binding ExpandCommand}"/>
                    <telerik:RadMenuItem Header="Collapse All Levels" Command="{Binding CollapseCommand}"/>
                </telerik:RadContextMenu>
            </telerik:RadContextMenu.ContextMenu>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="PreviewUnselected">
                    <Command:EventToCommand Command="{Binding Path=PreviewUnselectedCommand, Mode=OneWay}" PassEventArgsToCommand="True"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="PreviewSelected">
                    <Command:EventToCommand Command="{Binding Path=PreviewSelectedCommand, Mode=OneWay}" PassEventArgsToCommand="True"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </telerik:RadTreeView>

Expand Command:
private void ExpandAllChildren(MyTreeNode node, bool bExpandOrCollapse)
{
 
    foreach (MyTreeNode childNode in node.ChildNodes)
    {
        ExpandAllChildren(childNode, bExpandOrCollapse);
    }
 
    if (node.ChildNodes.Count > 0)
        node.IsExpanded = bExpandOrCollapse;
}
 
private RelayCommand _expandCommand;
public ICommand ExpandCommand
{
    get
    {
        if (_expandCommand == null)
        {
            _expandCommand = new RelayCommand(() =>
            {
                try
                {
                    UICursor = Cursors.Wait;
                    ExpandAllChildren(tvSelectedItem, true);
                }
                catch
                {
 
                }
                finally
                {
                    UICursor = Cursors.Arrow;
                }
            });
        }
 
        return _expandCommand;
    }
}

Thanks for any help.  Bob C.

1 Answer, 1 is accepted

Sort by
0
Zarko
Telerik team
answered on 11 May 2012, 04:03 PM
Hi Bob,
You could try to handle the RadTreeView's ItemContainerGenerator StatusChanged event and turn off the indicator there:
this.tvTree.ItemContainerGenerator.StatusChanged += this.OnItemContainerGeneratorStatusChanged;

private void OnItemContainerGeneratorStatusChanged(object sender, EventArgs e)
{
    var generator = sender as ItemContainerGenerator;
    if (generator != null && generator.Status == GeneratorStatus.ContainersGenerated)
    {
        this.mvm.IsBusy = false;
    }
}
Also I'd like to advise you to turn on the UI Virtualization because it will greatly improve the performance:
<telerik:RadTreeView ...           
              IsVirtualizing="True"
              ...>

If you have further questions please feel free to ask.

Kind regards,
Zarko
the Telerik team

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

Tags
TreeView
Asked by
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Answers by
Zarko
Telerik team
Share this question
or