Forum Discussion

tim_faron's avatar
tim_faron
Contributor
11 years ago

can i catch an property or method not supported error and continue

In my application I am dealing with a NavTree which is a Windows .NET Application.



I want the user to specify the node in the Tree to select and if the node is expandable just expand it  but not have them have to know if expand is required or not.



At the highest level, there is no method to know if a node is expanded or not .. and I would have to institute some complex logic to dig deep into the object ... 



In my function i want to do the following:



---

Tree.ExpandItem("items");

--- If it fails I want to then just call 

Tree.ClickItem("items");

and then continue on ...



The problem is ExpandItem in some cases will throw "method or property not supported error so a try / catch will not work .. I know about OnLogError event but that will not continue my script.



Any suggestions on what I might be able to do.











4 Replies

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    From the eror your posted it sounds like you can't expand it because it has no items contained in that particular tree. I will give you an example of a similar control in which I had previously encountered that issue and hopefully that gives you an idea of what you need to do to get this working:

    JScript example--




    function clicknode(o,i,c,k,p){


    if (!p){o.collapseall();}


    for (var n = 0;n < o.nodes.count;n++){


     if (lcase(o.nodes.item(n).text.olevalue) == lcase(i)){


      if (p){p.click(o.nodes.item(n).get_Bounds.X + 15,o.nodes.item(n).get_Bounds.Y + 15);}


      else{o.click(o.nodes.item(n).get_Bounds.X + 15,o.nodes.item(n).get_Bounds.Y + 15);}


      return;


      }


     //drill down


     if (o.nodes.item(n).nodes.count > 0){ //you need something like this here


      o.nodes.item(n).expand(); //syntax here will vary slightly for you


      if (!p){clicknode(o.nodes.item(n),i,'','',o);}


      else{clicknode(o.nodes.item(n),i,'','',p);}


      }


     }


    }


  • I tried this after your post and it seems in all cases the method is supported ..



    This is the error i get when I call it ...




    Exception encountered. Error


    The tree node cannot be expanded or collapsed.


    The node has no child nodes.



    To be more specific now that I am posting the error, it seem's like it would be hard for me, lots of object digging to determine if there are children or not ... 



    So i would love to be able to if i got this error to catch it and go ... but it's a TestComplete error so try/catch does not work ..



    Thanks for the help

  • Thanks Ryan .. I started looking into that approach .. I was just reluctly hoping i could get around do it but that is how I have to work with most of these .NET objects ...