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

How can I find out the number of nodes in a rad tree view

4 Answers 130 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Andrei
Top achievements
Rank 1
Andrei asked on 21 Nov 2013, 03:45 PM
Hi,

I'm trying to find out how many nodes are in a tree view and for this i'm using the following code:

var myApp= Pages.TelerikTreeViewFor.SilverlightApp;
Telerik.WebAii.Controls.Xaml.RadTreeView tree= myApp.XTreeViewRadtreeview;
tree.InvokeMethod(new AutomationMethod("ExpandAll", typeof(void)));
 
IList<Telerik.WebAii.Controls.Xaml.RadTreeView> items = tree.Find.AllByType<Telerik.WebAii.Controls.Xaml.RadTreeView>();
 
int nrNodes= items.Count();
Log.WriteLine("Number of nodes: "+ nrNodes);

The number of nodes i get in 0.
I'm runnig this code for: http://demos.telerik.com/silverlight/#TreeView/HierarchicalTemplate
Am i doing something wrong?
Can someone give me another example of how can i know the number of nodes in a treeview?

Thanks !

4 Answers, 1 is accepted

Sort by
0
Daniel
Top achievements
Rank 2
answered on 21 Nov 2013, 04:35 PM
var myApp = Pages.TelerikTreeViewFor.SilverlightApp;
 
Telerik.WebAii.Controls.Xaml.RadTreeView tree = myApp.XTreeViewRadtreeview;
 
Log.WriteLine(tree.AllNodes.Count.ToString());

'11/21/2013 11:34:39 AM' - LOG: 52

RadTreeView has a built in "AllNodes" member that you can then call Count on.

There is also an "RootNodes" which would return a count of 4.

Hopefully this is what you were looking for.
0
Andrei
Top achievements
Rank 1
answered on 22 Nov 2013, 07:40 AM
Hi Daniel,

Thanks for your quick answer.
Unfortunately the solution you provided doesn't work.
The problem is that the first time I navigate to http://demos.telerik.com/silverlight/#TreeView/HierarchicalTemplate , only 7 nodes of the tree view appear.
If i run the following script  it will find only the first 7 visible nodes.

var myApp= Pages.TelerikTreeViewFor.SilverlightApp;
Telerik.WebAii.Controls.Xaml.RadTreeView tree= myApp.XTreeViewRadtreeview;
tree.InvokeMethod(new AutomationMethod("ExpandAll", typeof(void)));
  
IList<Telerik.WebAii.Controls.Xaml.RadTreeView> items = tree.AllNodes;
Log.WriteLine("Number of nodes: "+ items.Count.ToString());

I would like to find all the nodes after expanding the tree (which should be 52 nodes in this example).
Is this possible ?
0
Accepted
Daniel
Top achievements
Rank 2
answered on 22 Nov 2013, 01:19 PM
I realize now the mistake I made which resulted in mine working.  The visual tree had already been refreshed as I re-ran the selected step only.

Here is how to fix it:
[CodedStep(@"")]
public void GetRadTreeNodes()
{
    var myApp = Pages.TelerikTreeViewFor.SilverlightApp;
    Telerik.WebAii.Controls.Xaml.RadTreeView tree = myApp.XTreeViewRadtreeview;
    Assert.IsNotNull(tree);
     
    tree.InvokeMethod(new AutomationMethod("ExpandAll", typeof(void)));
     
    //System.Threading.Thread.Sleep(2000);
    tree.Refresh();
     
    Log.WriteLine(tree.AllNodes.Count.ToString());
}


important line is "tree.Refresh()" which causes the Visual Tree to refresh, updating the node count.  You may need the sleep depending on how fast the Silverlight app refreshed.

Here is the run log:

Overall Result: Pass
------------------------------------------------------------
'11/22/2013 8:18:41 AM' - Using .Net Runtime version: '4.0.30319.18408' for test execution. Build version is '2013.1.1120.0'.
'11/22/2013 8:18:41 AM' - Starting execution....
'11/22/2013 8:18:41 AM' - Detected a Silverlight Test. Setting EnableSilverlight=True
'11/22/2013 8:18:48 AM' - Detected custom code in test. Locating test assembly: PCC_Demo2.dll.
'11/22/2013 8:18:48 AM' - Assembly Found: \\..\Test Studio Projects\PCC_Demo2\bin\PCC_Demo2.dll
'11/22/2013 8:18:48 AM' - Loading code class: 'PCC_Demo2.TelerikRadTree'.
------------------------------------------------------------
------------------------------------------------------------
'11/22/2013 8:18:48 AM' - Using 'InternetExplorer' version '10.0' as default browser.
'11/22/2013 8:18:48 AM' - 'Pass' : 1. Navigate to : 'http://demos.telerik.com/silverlight/#TreeView/HierarchicalTemplate'
'11/22/2013 8:18:49 AM' - LOG: 52
'11/22/2013 8:18:49 AM' - 'Pass' : 2. [GetRadTreeNodes] :
------------------------------------------------------------
'11/22/2013 8:18:49 AM' - Overall Result: Pass
'11/22/2013 8:18:49 AM' - Duration: [0 min: 1 sec: 525 msec]
------------------------------------------------------------
'11/22/2013 8:18:51 AM' - Test completed!



0
Andrei
Top achievements
Rank 1
answered on 25 Nov 2013, 07:21 AM
Yes, now it ok.
Thank you for your answer!
Tags
General Discussions
Asked by
Andrei
Top achievements
Rank 1
Answers by
Daniel
Top achievements
Rank 2
Andrei
Top achievements
Rank 1
Share this question
or