New to Telerik Test Studio Dev EditionStart a free 30-day trial

Go Through Each Node in a WPF RadTreeView

I would like to go through each node in a WPF RadTreeView until a match is made.

Solution

This is possible with a coded solution. You'll expand each node and refresh the tree until you find your match.

C#
    WpfApplication app = Manager.ActiveApplication;
    Assert.IsNotNull(app);
    Telerik.WebAii.Controls.Xaml.Wpf.RadTreeView tree = app.MainWindow.Find.ByName<Telerik.WebAii.Controls.Xaml.Wpf.RadTreeView>("treeView");
    Assert.IsNotNull(tree);
    
    string match = Data["ExtractedValue"].ToString();
    bool found = false;
    IList<Telerik.WebAii.Controls.Xaml.Wpf.RadTreeViewItem> items = tree.Find.AllByType<Telerik.WebAii.Controls.Xaml.Wpf.RadTreeViewItem>();
    
    while (found == false)
    {
        foreach (Telerik.WebAii.Controls.Xaml.Wpf.RadTreeViewItem tvItem in items)
        {
            try
            {
                if (tvItem.IsExpanded == false)
                {
                    tvItem.Expand();
                    tree.Refresh();
                }
            }
            catch (Exception ex)
            {
            }
    
            if (tvItem.Text.Contains(match))
            {
                Log.WriteLine("Found: " + tvItem.Text);
                found = true;
                break;
            }
    
            tree.Refresh();
        }
        if (found == true)
        {
            break;
        }
    }
In this article
Solution
Not finding the help you need?
Contact Support