Forum Discussion
in here study the SaveChildItems methoed
you may modify it and use for your purpose or
simply save to a file (as it is) and read that file.
Hi Mulgravetester,
I believe that you can use the aqString.Find method to check if the target item is in the list:
Res = aqString.Find(myMenuTree.wItems, myItem) If Res <> -1 Then Log.Message(myItem & " was found in string") Call myMenuTree.ClickItemR(myItem) end if
- Colin_McCrae10 years agoCommunity Hero
Does the wItem property just list the individual node names?
In which case, it may find a single element. But it won't validate that it exists in the correct place in the tree view.
So if child nodes, of child nodes, of child nodes, all have the same name (which is quite possible - happens quite frequently in the tree objects I test) then you may find a match, but it may not be the right one, or in the right place.
The way I do it with Delphi trees is to select the item (using a left click - a right click triggers different options) and then afterwards check that the current selection is what you asked it to click on. Using the full pipe locator, so you know you got the correct node. If it doesn't match, the node didn't exist.
If the node doesn't exist, it doesn't throw any sort of error for me? It just carries on regardless. So I don't even have to bother putting it inside a try/catch. But you could if a bad selection caused an error.
This is fine for me as left clicking an item is fine to simply see if it exists. You have to start double or right clicking before anything actually happens. Of course, your application may not work that way in which case this approach may not work.
- MulgraveTester10 years agoFrequent Contributor
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 itemif 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
nextcall myTree.ClickItemR(lastClickedItem) 'R-click the last item selected to open the context menu
- Colin_McCrae10 years agoCommunity Hero
Yep. That sounds pretty much like what I do.
Have you got to the r-click context menus yet? Not sure about your application, but on mine - Delphi - their behaviour is a bit weird. As in, how they spawn, what they're children of, and if they go several levels deep, how those child menus are generated and named.
Just shout if you want me to elaborate ....