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

RadTreeViewItem is expandable?

4 Answers 102 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stanislav
Top achievements
Rank 1
Stanislav asked on 02 Nov 2012, 12:29 AM
Hello all,

Is there any property in RadTreeViewItem control which will return me whether the element can be expanded or not?

Thank you.

Kind Regards,
Stanislav Hordiyenko

4 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 07 Nov 2012, 02:42 PM
Hello Stanislav,

Unfortunately there is no such property. However you can check the count of the child nodes and if the count is greater than 0, then the RadTreeViewItem is expandable. Here's a sample code:
RadTreeViewItem item = treeView.FindNodeByText("RadTreeViewItem1");
if (item.NodeElements.Count > 0)
{
    Log.WriteLine("The node is expandable");
}

Hope this helps!

All the best,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Stanislav
Top achievements
Rank 1
answered on 07 Nov 2012, 11:56 PM
Hello Plamen,

Unfortunately, your workaround isn't working. The code return 0 items for the first time once the application was started despite the fact that there are more than 11 RadTreeViewItems under the node. When I manually expand the items, this code works fine. I think this is because the RadTreeView is populated dynamically once I click on the node. I even tried to refresh the visual tree and other available functions. I think we definitely need the property which will return whether the node is expandable or not. I hope you will consider my suggestion.

Are there any other options to solve this issue?

Thank you.

Kind Regards,
Stanislav Hordiyenko
0
Plamen
Telerik team
answered on 12 Nov 2012, 03:47 PM
Hi Stanislav,

I discussed this with our developers and they approved your request. You can track its progress and vote for it here: Public URL.

In the meantime, as a workaround, you can try to determine whether the node is expandable or not by verifying whether the arrow next to the node exists or not. Here's an example:
RadTreeView treeView = Pages.ASPNETTreeViewDemo.ContentPlaceHolder1RadTreeView1Div;
Assert.IsNotNull(treeView);
 
foreach (RadTreeNode node in treeView.AllNodes)
{
    HtmlSpan expandArrow = node.Find.ByAttributes<HtmlSpan>("class=rtPlus");
    if (expandArrow == null)
    {
        node.Find.ByAttributes<HtmlSpan>("class=rtIn").MouseClick();
    }
}

As you can see in this video, I'm using the code above to click on all items that are not expandable. 


All the best,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Stanislav
Top achievements
Rank 1
answered on 12 Nov 2012, 10:18 PM
Hello Plamen,

Thank you for your workaround. Before I start to navigate in RadTreeView, I collapse all RadTreeViewItems and then just invoke double click on each element:

public void NavigateByPath(string path)
{
    var pathItemList = path.Split(new char[] { '>' });
    var homeTreeView = NativeWindow.Find.ByType<RadTreeView>();
    homeTreeView.InvokeMethod(new AutomationMethod("CollapseAll", typeof(void)));
 
    foreach (var pathItem in pathItemList)
    {
        homeTreeView.Refresh();
        var item = homeTreeView.FindNodeByText(pathItem.Trim());
        item.ScrollToVisible();
        item.User.Click(MouseClickType.LeftDoubleClick);
        Thread.Sleep(1000);
    }
}

Maybe this code will be helpful for someone too.

Thanks.

Kind Regards,
Stanislav Hordiyenko
Tags
General Discussions
Asked by
Stanislav
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Stanislav
Top achievements
Rank 1
Share this question
or