Grabbing All TreeViewItem's from TreeView

8 posts, 0 answers
  1. Aaron
    Aaron avatar
    31 posts
    Member since:
    May 2016

    Posted 12 May Link to this post

    I have a TreeView that allows for multiple selection of TreeViewItem's. We don't use RadTreeView/Item, the project uses ArtOfTest.WebAii.Controls.Xaml.Wpf.TreeView/Item controls.

    My issue is, I have a screen that when it loads, the same TreeViewItem isn't necessarily selected, and I need to select a specific one based on some text in the name of it.

    So for example, in Screenshot_1, that first item is selected but I actually need the second one selected (there could be more than two items, that is just currently what I have in my sample), but the first item might not always be selected. There could be nothing selected on the screen load.

    What I was thinking I would like to do is loop through the TreeView and deselect everything that is expanded, unless it has the text I'm looking for, in which case it should expand/select it.

    Been working on this for a while and can't seem to figure it out...

  2. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    251 posts

    Posted 17 May Link to this post

    Hi Aaron,

    Thank you for choosing Telerik Test Studio.

    I have a demo WPF application installed on my machine with all controls you could use. I recorded a sample code against that application and will share it here.

    WpfApplication app = Manager.ActiveApplication;
            Assert.IsNotNull(app);
            Telerik.WebAii.Controls.Xaml.Wpf.RadTreeView tree = app.MainWindow.Find.ByName<Telerik.WebAii.Controls.Xaml.Wpf.RadTreeView>("xTreeView");
            Assert.IsNotNull(tree);
                 
            IList<Telerik.WebAii.Controls.Xaml.Wpf.RadTreeViewItem> items = tree.Find.AllByType<Telerik.WebAii.Controls.Xaml.Wpf.RadTreeViewItem>();
            Log.WriteLine(items.Count.ToString());
                foreach (Telerik.WebAii.Controls.Xaml.Wpf.RadTreeViewItem treeItem in items)
                {
                    if(treeItem.Text=="FISS GROUP")
                    {
                        treeItem.User.Click();
                       
                    }
     
    The above would work if the items in the RadTreeView would be checked when clicked. If your application does not work that way you could look for the check box in the item and click on it. In my example I have toggle buttons and no check boxes (see the screenshot). To click on that button in my scenario I inserted the following under the if statement: 


    ToggleButton myButton = treeItem.Find.ByType<ToggleButton>();
    myButton.User.Click();

    Please try this on your end and let me know if it was helpful. If you still experience troubles and cannot find the exact elements to click on, please make a  screenshot of the DOM tree for the element you need and send it over this thread to continue the investigation. 

    Hope to hear from you soon. 

    Regards,
    Elena Tsvetkova
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  3. Aaron
    Aaron avatar
    31 posts
    Member since:
    May 2016

    Posted 17 May Link to this post

    Hi Elena,

    Thanks for getting back to me.

    Unfortunately that did not work for me. I'm actually not using the RadTreeView/RadTreeViewItem I use ArtOfTest.WebAii.Controls.Xaml.Wpf.TreeView/Item control. That being said I tried the code with both iterations and neither worked for me. It returned 0 elements. (I did change the name of that Find to 'tree' as it is in my DOM).

    Attached is my DOM screenshot. 

  4. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    251 posts

    Posted 19 May Link to this post

    Hi Aaron,

    Thank you for the shared details. i am sorry that the provided code didn't work for you. Please let me know if you could provide us your application since it is quite difficult to write a code sample without the actual application. If this wouldn't be possible we could try to "blindly" rework the code but there is no guarantee it will be working with your application. 

    Please let me know your input on the topics above. 

    Regards,
    Elena Tsvetkova
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  5. Aaron
    Aaron avatar
    31 posts
    Member since:
    May 2016

    Posted 19 May in reply to Elena Tsvetkova Link to this post

    Hi Elena,

    Unfortunately we currently don't have a live version of our application that could be accessed for testing purposes. All of our test data is set-up internally.

    If you don't mind trying to figure it out still, I would definitely like to find a solution if possible. That being said, we have a small work around, so if we can't figure something out it definitely isn't the end of the world.

    Thanks, Aaron

  6. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    251 posts

    Posted 20 May Link to this post

    Hello Aaron,

    I don't mind to assist you of course but I will need at least a sample application using the same controls so that I could try to write the required code. If you could prepare such and send it I will be glad to try it out. 

    Regards,
    Elena Tsvetkova
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  7. Aaron
    Aaron avatar
    31 posts
    Member since:
    May 2016

    Posted 20 May in reply to Elena Tsvetkova Link to this post

    Hi Elena,

    Unfortunately I currently don't have the means of doing that either.

    However, we are going to talk to our Dev team and see if we can get a license and live sample database that we can use to provide to you guys whenever we need assistance. It has stunted us a few times, and would definitely make things a lot easier for both us and you guys whenever we need to interact.

    Like I said earlier, it really isn't a big deal right now because we have a work around, but I'll be sure to post on this again and open it back up to try and solve it when I have something I can provide you!

    Thanks, Aaron

  8. Elena Tsvetkova
    Admin
    Elena Tsvetkova avatar
    251 posts

    Posted 25 May Link to this post

    Hello Aaron,

    I am glad to hear you have a workaround and are able to work flawlessly. I appreciate your effort to create a test application that will ease our future cooperation.

    Please do not hesitate to contact Telerik Test Studio in case of any other future queries as well. 

    Regards,
    Elena Tsvetkova
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top