Forum Discussion

OV's avatar
OV
Frequent Contributor
7 years ago

How to retrieve child obejcts

Hi,

 

I'm trying to retrieve a child objects and check their existence under their parent object. how do i do it? anything i tried failed

 

I know it is possible to achieve it using FindAllChildren but find it hard to implement in this case as sometimes i'm picking a property to search for and a value and get an error .

 

The child objects are created dynamically and i should make sure the right name does appear under the right parent.

 

Attached is a screen shot of the objects tree.

 

The children i'm aiming for are the printer, printer 2 .......

 

The peace of code so far

 

for(k = 1 ; k <= Aliases.QuickDesign_ConfigurationManager.HwndSource_This2.This.FunctionalItemsControl.Tree.TreeViewItem.ChildCount - 2 ; k++)
{
var ExistingPrintersList = Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.FunctionalItemsControl.Tree.FindAllChildren("ClrClassName", "TreeViewItem", 4).toArray()
// Verify Printer item exists under each device

//if(Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.FunctionalItemsControl.Tree.WPFObject("TreeViewItem", "", j).Exists)
Pass(Aliases.QuickDesign_ConfigurationManager.HwndSource_This2.This.FunctionalItemsControl.Tree.TreeViewItem.EditableTextBlock.WPFObject("Grid", "", 1).WPFObject("TextBlock", "Printer " + k, 1).Text + " was added properly under " + Device)

Fail(Aliases.QuickDesign_ConfigurationManager.HwndSource_This2.This.FunctionalItemsControl.Tree.TreeViewItem.EditableTextBlock.WPFObject("Grid", "", 1).WPFObject("TextBlock", "Printer " + k, 1).Text + " wasn't added properly under " + Device)
}

 

Let me know if you need any more information to sort this one out.

 

Thx,

 

OV

 

 

3 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    ExistingPrintersList is an array.  You want to check then each element in that array to see if it has the text you're looking for.  So, it's another for loop looping through the new array.

     

    You say you're getting an error... what error?

    • OV's avatar
      OV
      Frequent Contributor

      Hi Robert,

       

      Thanks again for the help.

       

      I've manage to create the array/s but there's still something i can't understand

       

      This is my line of code to create the array for the first project - WPFObject("TreeViewItem", "", 1)

       

      x = Aliases.QuickDesign_ConfigurationManager.BreadsScrumpTree.FunctionalItemsControl.Tree.WPFObject("TreeViewItem", "", 1).FindAllChildren("WPFControlText" , "Printer*" , 20).toArray()

       

      Now, since each Project can have different number of arrays I need every time i want to check the number of printers under specific project to change this value WPFObject("TreeViewItem", "", 1) to WPFObject("TreeViewItem", "", 2) or WPFObject("TreeViewItem", "", 3), etc. somehow when using WPFObject("TreeViewItem", "", 2) i'm getting the right results - Printer 2, Printer, Printer 3 (Wrong order starting from the middle one I would also like to know why the order is wrong) when using WPFObject("TreeViewItem", "", 1) i'm getting 4 items in the array instead of only 2 - Printer 2, Printer 2, Printer, Printer  and for WPFObject("TreeViewItem", "", 3) there's no array created because (I Guess) there are no printers under this project. Can you please explain why and where do i get it wrong?

      WPFObject("TreeViewItem", "", *) is the only tree junction that i can destinguesh netween the projects - 

      WPFObject("TreeViewItem", "", 1) - for project 1

      WPFObject("TreeViewItem", "", 2) - for project 2

      WPFObject("TreeViewItem", "", 3) - for project 3

      ............

       

      See attached

       

      Thanks

       

      • OV's avatar
        OV
        Frequent Contributor

        OK I've managed to solve it with the following code:

         

        function CheckPrintersUnderProjects()
        {
        PropArray = "WPFControlText"
        ValuesArray = "Printer*"
        ProjectsArray = Aliases.QuickDesign_ConfigurationManager.HwndSource_This2.This.FunctionalItemsControl.Tree.FindAllChildren("ClrClassName", "TreeViewItem", 1).toArray()
        for(j = ProjectsArray.length - 1 ; j >= 0 ; j--)
        {
        Log.AppendFolder("Printers Under " + ProjectsArray[j].DataContext.Project.Name.OleValue)
        PrintersArray = ProjectsArray[j].FindAllChildren("WPFControlText", "Printer*", 6).toArray()
        for( i = 0; i < PrintersArray.length; i++)
        Log.Message(ProjectsArray[j].Items.Item(i).Name.OleValue)
        Log.PopLogFolder()
        }
        }

         

        But i must say that was cumbersome and took me quite a lot of time :-/

         

        Do you think there's better way to do it?

         

        I'm just afraid i'm working in the wrong way and don't want to spend time in the future.

         

        Thx