Forum Discussion

MulgraveTester's avatar
MulgraveTester
Frequent Contributor
10 years ago

How can I test if a menu tree item exists before clicking it

I am working with a SysTreeView32 object. The tree structure in this object will change dynamically so I want to test if the menu item exists before r-clicking it. There is no "exists" property for i...
  • MulgraveTester's avatar
    MulgraveTester
    10 years ago

    Thanks all for you replies and for pulling me back to reality. After posting I wrote an elaborate set of functions to drill down through the tree to see if the item existed. All this was overkill.

     

    What I was actually trying to do was click several items in the tree and right-click the last item in order to bring up a context menu. I had to know that the last item I clicked was valid so that I r-clicked in the correct place.

     

    If I try and click an item that doesn't exist then an error is logged. I just wrote an event handler to ignore it. 

    Once an item is clicked I inspect if the item matches the wselection (which only lists the last item clicked). So the end solution looks something like this -

     

    selectionArray = Array("|A|B|1","|A|B|2","A|B|3")

    modifierKey = skNoShift
    for each selection in selectionArray
      call myTree.ClickItem(selection, modifierKey) 'Click or Ctrl+Click each item

      if strcomp(myTree.wSelection, selection)>=0 then 'Test the the item is now selected
        modifierKey = skCtrl
        lastClickedItem = selection    
      else
        call log.Warning("Tree menu item (" & selection & ") was not found.")
      end if
    next

    call myTree.ClickItemR(lastClickedItem) 'R-click the last item selected to open the context menu