Antonio Linares wrote:Frances, Detlef,
Here you have a working example:
- Code: Select all Expand view
#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 "DbfTree"
@ 0, 0 XBROWSE oBrw OF oWnd LINES CELL
oBrw:SetTree( BuildTree() )
oBrw:CreateFromCode()
oBrw:aCols[ 1 ]:cHeader = "State"
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 := RecNo()
TREE
cState = Customer->State
else
if cState != Customer->State
ENDTREE
cState = Customer->State
_TreeItem( Customer->State ):Cargo := RecNo()
TREE
endif
endif
if Customer->State == cState
_TreeItem( Customer->City ):Cargo := RecNo()
endif
SKIP
enddo
ENDTREE
ENDTREE
GO TOP
return oTree
/*
*
* XbTree2.Prg
* 24-12-2010 08:39 PM
*
*/
#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"
//----------------------------------------------------------------------------//
REQUEST DBFCDX
#xtranslate bmp( <c> ) => "c:\fwh\bitmaps\16x16\" + <c> + ".bmp"
//----------------------------------------------------------------------------//
function Main()
CreateTestData()
TreeBrowse()
return (0)
//----------------------------------------------------------------------------//
init procedure PrgInit
SET DATE ITALIAN
SET CENTURY ON
SET TIME FORMAT TO "HH:MM:SS"
SET EPOCH TO YEAR(DATE())-50
SET DELETED ON
SET EXCLUSIVE OFF
RDDSETDEFAULT( "DBFCDX" )
XbrNumFormat( 'I', .t. )
SetKinetic( .f. )
SetGetColorFocus()
return
//----------------------------------------------------------------------------//
exit procedure PrgExit
SET RESOURCES TO
return
//----------------------------------------------------------------------------//
static function TreeBrowse
local oDlg, oBrw, oFont
local aTot := { 0, 0 }
local aColors := { { CLR_WHITE, CLR_GREEN }, ;
{ CLR_BLACK, RGB(255,255,180) }, ;
{ CLR_BLACK, CLR_WHITE } }
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
DEFINE DIALOG oDlg SIZE 600,500 PIXEL ;
TITLE "Xbrowse Tree" FONT oFont
@ 10,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg ;
CELL LINES NOBORDER FOOTERS
oBrw:SetTree( MakeTree( aTot ), { bmp( "open" ), bmp( "folder" ), bmp( "spurce" ) } )
ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 1 ] PICTURE "999,999,999" HEADER "Sales"
ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 2 ] PICTURE "999,999,999" HEADER "Margin"
WITH OBJECT ( oBrw:Percent := { || oBrw:Margin:Value / oBrw:Sales:Value * 100 } )
:cHeader := "%"
:cEditPicture := "999.99 %"
:bFooter := { || aTot[ 2 ] / aTot[ 1 ] * 100 }
END
WITH OBJECT oBrw
:bClrStd := { || aColors[ oBrw:oTreeItem:nLevel ] }
:Item:cHeader := "Area"
:Sales:bFooter := { || aTot[ 1 ] }
:Margin:bFooter := { || aTot[ 2 ] }
:nStretchCol := 1
END
oBrw:CreateFromCode()
oBrw:oTree:OpenAll()
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
//----------------------------------------------------------------------------//
static function MakeTree( aTot )
local oTree
local cRegion, cCountry
local oRegion, oCountry
USE SALEDATA NEW ALIAS SD SHARED READONLY
SET ORDER TO TAG AREA
GO TOP
TREE oTree
do while !SD->( eof() )
TREEITEM oRegion PROMPT SD->REGION CARGO { 0, 0 }
cRegion := SD->REGION
TREE
do while SD->REGION == cRegion
TREEITEM oCountry PROMPT SD->COUNTRY CARGO { 0, 0 }
cCountry := SD->COUNTRY
TREE
do while SD->COUNTRY == cCountry
TREEITEM SD->CITY CARGO { SD->SALES, SD->MARGIN }
oCountry:Cargo[ 1 ] += SD->SALES
oCountry:Cargo[ 2 ] += SD->MARGIN
SD->( DbSkip( 1 ) )
enddo
ENDTREE
oRegion:Cargo[ 1 ] += oCountry:Cargo[ 1 ]
oRegion:Cargo[ 2 ] += oCountry:Cargo[ 2 ]
enddo
ENDTREE
aTot[ 1 ] += oRegion:Cargo[ 1 ]
aTot[ 2 ] += oRegion:Cargo[ 2 ]
enddo
ENDTREE
CLOSE SD
return oTree
//----------------------------------------------------------------------------//
static function createTestData()
field REGION,COUNTRY,CITY
local aCols := { ;
{ "REGION", "C", 10, 0 }, ;
{ "COUNTRY", "C", 10, 0 }, ;
{ "CITY", "C", 10, 0 }, ;
{ "SALES", "N", 10, 0 }, ;
{ "MARGIN", "N", 10, 0 } }
local i,n,m
DbCreate( "SALEDATA.DBF", aCols )
USE SALEDATA EXCLUSIVE
for i := 1 to 20
APPEND BLANK
n := HB_RandomInt( 1, 4 )
REGION := { "AMERICAS","EUROPE","ASIA","OCEANA" }[ n ]
m := HB_RandomInt( 1, 2 )
COUNTRY := {{"USA","CANADA"},{"ITALY","SPAIN"},{"CHINA","INDIA"},{"AU","NZ"}}[ n, m ]
CITY := "City " + StrZero( i, 2 )
n := HB_Random( 10000,1000000 )
m := HB_Random( 1000, n * 0.1 )
FIELD->SALES := n
FIELD->MARGIN := m
next i
INDEX ON REGION+COUNTRY+CITY TAG AREA
CLOSE DATA
return nil
//----------------------------------------------------------------------------//
nageswaragunupudi wrote:Please also see the samples I posted here, using related DBFs to show as tree
viewtopic.php?f=6&t=20761&p=110295#p110295
fraxzi wrote:nageswaragunupudi wrote:Please also see the samples I posted here, using related DBFs to show as tree
viewtopic.php?f=6&t=20761&p=110295#p110295
Thanks Mr. RAO... i've been waiting for your reply.
Your sample shows 2 level... i'm having problem with multiple level..
I hope you have a similar example.
Kind regards,
Frances
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 64 guests