Forum Discussion

Oferv's avatar
Oferv
Super Contributor
6 years ago

Fail to get Treeview array values

Hi,

I have problem to get values from a teeview array, I can see the array created in the debug window but i'm failing to get the actuall value fro array items.

 

the code line i'm using to create the array is 

PatternsNumber = Aliases.CCM.BreadScrumbTree.AutomationPatternsControl.Tree.FindAll("ClrClassName", "TreeViewItem", 1)  and i'm using something like PatternsNumber [0].DataContext.DisplayName to get the string name display in the UI. that doesn't get anything.

 

Anyone knows why?

 

Thanks

5 Replies

  • Oferv's avatar
    Oferv
    Super Contributor

    Hi,

    I have problem to get values from a teeview array, I can see the array created in the debug window but i'm failing to get the actuall value fro array items.

     

    the code line i'm using to create the array is 

    PatternsNumber = Aliases.CCM.BreadScrumbTree.AutomationPatternsControl.Tree.FindAll("ClrClassName", "TreeViewItem", 1)  and i'm using something like PatternsNumber [0].DataContext.DisplayName to get the string name display in the UI. that doesn't get anything.

     

    Anyone knows why?

     

    Thanks

    • Oferv's avatar
      Oferv
      Super Contributor

      Hi Robert,

       

      I'm using java script and did saw the comment you attached and did tried to use it (not sure i did it properly thou).

      When the script run I did put a breakpoint exactly after the array is being created but, when looking on the variable in the watch list I can expand it and see the array items (tc says their type is string) but when trying to display one of the items for example PatternsNumber (0).Name etc. TC doesn't show any text

       

      Can you please confirm the way i used to convert the array is correct?

       

      please see attached

       

      Thanks

       

      • Oferv's avatar
        Oferv
        Super Contributor

        Ok I got it, i know what was my mistake and it's working now.

         

        function Test1()
        {
         
         PatternsNumber = Aliases.CCM.BreadScrumbTree.AutomationPatternsControl.Tree.FindAll("ClrClassName", "TreeViewItem", 1)
          PatternsNumber = PatternsNumber.toArray()
          PatternsNumber[0].click()
        }

         

        I have another question, why if i ask him to click item[0] it click the last item in the UI?

         

        Thanks

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    Are you sure that FindAll is returning a non-empty array?  I'd put a breakpoint in there somewhere and inspect PatternsNumber after the FindAll call and make sure that there are contents in there.  Also, what language are you writing in? Is this JScript, C++Script or C#Script?  If so, note the following remarks from the documentation.

    Result Value

    An array of the objects that have the specified values of the specified properties. The returned collection includes the testObj object if it matches the search conditions.

    Note for JScript, C#Script and C++Script users: The array returned by the FindAll method is in the safe array format, which is not compatible with standard JScript arrays. To use such an array in JScript, C#Script or C++Script code, you need to convert it to the native format using the toArray method of the variant array (see the examples below).