LB Booster
Programming >> BASIC code examples >> LBW-created Tree View
http://lbb.conforums.com/index.cgi?board=code&action=display&num=1428655493

LBW-created Tree View
Post by Richard Russell on Apr 10th, 2015, 08:44am

If you use Liberty BASIC Workshop to create the outline code for a Tree View, it incorporates a SUB treeview1Click which is documented thus: "You must SendMessageA for each node ID to see if it is selected". The implication is that if you have a large tree, with maybe hundreds or thousands of nodes, you must cycle through every node ID checking to see if it is selected (clicked) or not.

In fact there's a much easier method. You can directly ask the Tree View control which node is currently selected; this is just a single message, however large the tree is:

Code:
Sub TreeViewClick
    calldll #user32, "SendMessageA", hwndTreeView1 as ulong, _
      _TVM_GETNEXTITEM as long, _TVGN_CARET as long, _
      0 as long, sel as long
    if sel <> SelectedNode then
      SelectedNode = sel
      notice "Clicked node ";sel
    end if
End Sub 

You would typically call this SUB from a timer. The variable SelectedNode must be declared as a GLOBAL for the click-detection to work.

Richard.