INDEX v1.20 |
509 Center Bay City, Michigan Sales (989) 892-9242             Support (989) 686-8860 ANSI Standard PL/B Language TREEVIEW |
TREEVIEW
4/22/2002... just starting this section.
Testing is being done in the Utilities system under TV-MMCC.
PROCESSING TREEVIEW EVENTS
Like Listviews, there is an important thing to know about treeviews built in the designer. Events generate a series of values which are stored by the form in local variables. To get these back into a mainline program you have to move them from the local variable to a general variable which the mainline can see.
For example Clicking on an item in the TreeView generates a CLICK event. If you want to know the details of this click you must capture the data within the code in the form itself.
We use the following code on each event that we want to process.MOVE #EventType, EventType MOVE #EventResult, EventResult (the row number) MOVE #EventObjId, EventObjId MOVE #EventChar, EventChar MOVE #EventMod, EventMod
TREEVIEW DRAG DROP
There is no specific drag drop. But you can simulate the action by using the MOUSEDOWN and MOUSEUP events. On each of these you grab EventResult and split it up to get the H:V positions of the mouse. Then you use the ItemHitTest method to translate that H:V coordinate into the handle of the line clicked on. Using that data you can get data from the lines.tv_mousedown DISPLAY "TV MOUSE DOWN " CALL CLEAR_PENDING_INFO ;Start over on any mouse DOWN CALL GET_EVENT_STUFF ;get the associated data MOVE TV_HANDLE,FROM_HANDLE ;the new position. RETURN . tv_mouseup DISPLAY "TV MOUSE UP "; ;this is same as a DROP CALL GET_EVENT_STUFF ;identify line they DROPPED on MOVE TV_HANDLE,TO_HANDLE ;this is line handle CALL DROP_ON_PRESS_LINE RETURN . get_event_stuff MOVE EventResult,WORK11 UNPACK WORK11,WORK03,#H,#V F_TV1.ItemHitTest GIVING TV_HANDLE: USING #H, #V F_TV1.GetItemText GIVING TV_DATA USING TV_HANDLE RETURN
Here's a routine from Gerhard Weiss as it appeared on the Sunbelt message board. This was posted by Matthew in response to a request from Paul Fuh:Bored? Itching for a challenge? How about creating a robust routine FindItem for Treeview similar to Listview.FindItem. Routine should try not have limitations on tree levels. Maybe the only limitation allowed is 65535 tree levels.I'm posting it here without review. Just don't want to lose track of it:Gerhard may recognize this logic (its plagiarized from the movetree logic done a long time ago). MatthewFText DIM ^ FHandle INTEGER ^ PStructTV TREEVIEW ^ rlngFromHWnd INTEGER 4 rlngToHWnd INTEGER 4 . lngFromChildItemHWnd INTEGER 4 lngToInsertItemHWnd INTEGER 4 . strItemText DIM ^80 . lngFromRootHWnd INTEGER 4 Findtree ROUTINE PStructTV,FText,FHandle DEBUG PStructTV.GetNextItem GIVING lngFromRootHWnd USING 0,0 ;root item MOVE lngFromRootHWnd,rlngFromHWnd . LOOP PStructTV.GetItemText GIVING strItemText USING *Item=rlngFromHWnd IF (strItemText = FText) MOVE rlngFromHWnd, FHandle SETFLAG EQUAL BREAK ENDIF . PStructTV.GetNextItem GIVING lngFromChildItemHWnd: USING *Item=rlngFromHWnd: *Code=4 ; child . IF (lngFromChildItemHWnd!=0) MOVE lngFromChildItemHWnd,rlngFromHWnd MOVE lngToInsertItemHWnd,rlngToHWnd ELSE LOOP UNTIL (rlngFromHWnd=lngFromRootHWnd) MOVE rlngFromHWnd,lngFromChildItemHWnd PStructTV.GetNextItem GIVING rlngFromHWnd: USING *Item=rlngFromHWnd: *Code=1 ; next UNTIL (rlngFromHWnd!=0) . PStructTV.GetNextItem GIVING rlngFromHWnd: USING *ITem=lngFromChildItemHWnd: *Code=TVGN_PARENT . PStructTV.GetNextItem GIVING rlngToHWnd: USING *Item=rlngToHWnd: *Code=TVGN_PARENT . REPEAT ENDIF IF ( lngFromRootHWnd = rlngFromHWnd ) PStructTV.GetNextItem GIVING lngFromRootHWnd: USING *Item=rlngFromHWnd: *Code=1 ; next MOVE lngFromRootHWnd,rlngFromHWnd ENDIF IF ( rlngFromHWnd = 0) SETFLAG NOT EQUAL BREAK ENDIF REPEAT RETURN