RadTreeViewItem is expandable?

5 posts, 0 answers
  1. Stanislav
    Stanislav avatar
    1 posts
    Member since:
    May 2012

    Posted 01 Nov 2012 Link to this post

    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
  2. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 07 Nov 2012 Link to this post

    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
  3. Stanislav
    Stanislav avatar
    1 posts
    Member since:
    May 2012

    Posted 07 Nov 2012 Link to this post

    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
  4. Plamen
    Admin
    Plamen avatar
    8 posts

    Posted 12 Nov 2012 Link to this post

    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
  5. Stanislav
    Stanislav avatar
    1 posts
    Member since:
    May 2012

    Posted 12 Nov 2012 Link to this post

    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
Back to Top