After a while without any suggestions, I'm thinking perhaps I did not explain my question well enough. Suppose I want to order this tree below by the 2nd column of each parent branch (that branch is the state name with folder bmp). This sample code is from xbrwTree.prg on the Samples folder. Notice I only changed a line to include a 2nd column on each parent branch with a random number between 0 and 1000.
Code: Select all
#include "FiveWin.ch"
#include "xbrowse.ch"
function Main()
local oWnd, oBrw
USE Customer
INDEX ON Field->State TO State
SET ORDER TO "State"
GO TOP
DEFINE WINDOW oWnd TITLE "DBF shown as a tree with XBrowse"
@ 0, 0 XBROWSE oBrw OF oWnd LINES CELL
oBrw:SetTree( BuildTree(), { "open", "close", "go" } )
ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 1 ] HEADER "Last"
ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 2 ] HEADER "First"
oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW
oBrw:CreateFromCode()
oBrw:aCols[ 1 ]:cHeader = "State & City"
oWnd:oClient = oBrw
ACTIVATE WINDOW oWnd
return nil
static function BuildTree()
local oTree, cState
TREE oTree
while ! Eof()
if Empty( cState )
_TreeItem( Customer->State ):Cargo := { hb_randomInt(1000), Space( 20 ) } //<<---- changed this line
TREE
cState = Customer->State
else
if cState != Customer->State
ENDTREE
cState = Customer->State
_TreeItem( Customer->State ):Cargo := { hb_randomInt(1000), Space( 20 ) } //<<---- and this line
TREE
endif
endif
if Customer->State == cState
_TreeItem( Customer->City ):Cargo := { Customer->Last, Customer->First }
endif
SKIP
enddo
ENDTREE
ENDTREE
GO TOP
return oTree
Is there a way to order this tree by the random number on column #2? The child branches would have to stay attached to its original parent branch. Any suggestions?
Thank you,
Reinaldo