I show only the first and second level and not all 3 levels
cCodice = alltrim(TABMAG->CODICE)
nLevel1:= right(alltrim(cCodice),2)
nLevel2:= right(alltrim(cCodice),4)
nLevel3:= right(alltrim(cCodice),8)
sample :
01 Hardware
0101 Monitors
01010001 Lcd
0102 Keyboads
01020001 Keyb qwrty
The tree run ok only I'm seeing an error on second level
here a small test with data
- Code: Select all Expand view
#include 'fivewin.ch'
#include 'colors.ch'
#include 'xbrowse.ch'
#include "constant.ch"
REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ORDKEYNO,ORDKEYCOUNT,ORDCREATE,ORDKEYGOTO
Function test()
Local odlg,oBrw,oFont
Local nBottom := 24
Local nRight := 88
Local nWidth := Max( nRight * DLG_CHARPIX_W, 180 )
Local nHeight := nBottom * DLG_CHARPIX_H
RddSetDefault( "DBFCDX" )
Create_Data()
USE TABMAG
INDEX ON Field->CODICE TO Codice
SET ORDER TO "Codice"
GO TOP
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE nWidth, nHeight PIXEL FONT oFont
@ 20,10 XBROWSE oBrw SIZE -10,-10 PIXEL OF oDlg LINES CELL
oBrw:SetTree( BuildTree2(), { "open", "close", "go" } )
ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 1 ] HEADER "Descrizione"
oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW
oBrw:lRecordSelector := .F. // .t.
oBrw:lAllowRowSizing := .F.
oBrw:lColDividerComplete := .F. // .f.
oBrw:lAllowColSwapping := .F.
oBrw:lAllowColHiding := .F.
oBrw:lFastEdit := .F.
oBrw:nRowDividerStyle := LINESTYLE_NOLINES
oBrw:nColDividerStyle := LINESTYLE_NOLINES
oBrw:CreateFromCode()
oBrw:aCols[ 1 ]:cHeader = "Codice"
ACTIVATE DIALOG oDlg CENTERED
RELEASE FONT oFont
return nil
static function BuildTree2()
local oTree, cCodice
TREE oTree
TABMAG->(dbgotop())
while ! Eof()
cCodice = alltrim(TABMAG->CODICE)
nLevel1:= right(alltrim(cCodice),2)
nLevel2:= right(alltrim(cCodice),4)
nLevel3:= right(alltrim(cCodice),8)
//nlevel1
do while Left( alltrim(TABMAG->CODICE), 2 ) == nLevel1 .and. ! eof()
_TreeItem( TABMAG->CODICE ):Cargo := { TABMAG->Desc }
TREE
TABMAG->(dbskip())
//nlevel2
do while Left( alltrim(TABMAG->CODICE), 2) == nLevel2 .and. ! eof()
_TreeItem( TABMAG->CODICE ):Cargo := { TABMAG->Desc }
TREE
TABMAG->(dbskip())
//nlevel3
do while Left( alltrim(TABMAG->CODICE), 2 ) == nLevel3 .and. ! eof()
_TreeItem( TABMAG->CODICE ):Cargo := { TABMAG->Desc }
TABMAG->(dbskip())
Enddo
ENDTREE
Enddo
ENDTREE
ENDDO
ENDDO
ENDTREE
GO TOP
return oTree
Function Create_Data()
local afields_Tabelle := { {'Chiave' ,'C',005,000},;
{'Codice' ,'C',008,000},;
{'Desc' ,'C',050,000},;
{'Num1' ,'N',016,000},;
{'Num2' ,'N',016,000},;
{'Num3' ,'N',002,000},;
{'Num4' ,'N',002,000},;
{'Num5' ,'N',016,000},;
{'Num6' ,'N',001,000},;
{'Num7' ,'N',001,000},;
{'Alfa1' ,'C',008,000},;
{'Alfa2' ,'C',008,000},;
{'Alfa3' ,'C',008,000},;
{'Alfa4' ,'C',008,000},;
{'Alfa5' ,'C',008,000},;
{'Alfa6' ,'C',040,000},;
{'Dat1' ,'D',008,000}}
cDir:=""
DbCreate(cDir+'TA',afields_Tabelle,'DBFCDX')
close all
use &(cDir+'TA') new
select TA
if FILE(cDir+'TABMAG.DBF')
delete file &(cdir+'TABMAG.cdx')
append from &(cdir+'TABMAG')
dbcommitall()
close all
delete file &(cdir+'TABMAG.dbf')
endif
close all
rename &(cdir+'TA.dbf') to &(cdir+'TABMAG.dbf')
USE TABMAG ALIAS TABMAG
IF TABMAG->(eof())
TABMAG->(DbAppend())
Replace TABMAG->Chiave with "MERCE"
Replace TABMAG->Codice with "01"
Replace TABMAG->Desc with "Hardware"
TABMAG->(DbAppend())
Replace TABMAG->Chiave with "MERCE"
Replace TABMAG->Codice with "02"
Replace TABMAG->Desc with "Software"
TABMAG->(DbAppend())
Replace TABMAG->Chiave with "MERCE"
Replace TABMAG->Codice with "0101"
Replace TABMAG->Desc with "Monitors"
TABMAG->(DbAppend())
Replace TABMAG->Chiave with "MERCE"
Replace TABMAG->Codice with "0102"
Replace TABMAG->Desc with "KeyBoards"
TABMAG->(DbAppend())
Replace TABMAG->Chiave with "MERCE"
Replace TABMAG->Codice with "01020001"
Replace TABMAG->Desc with "Keyboard qwerty"
TABMAG->(DbAppend())
Replace TABMAG->Chiave with "MERCE"
Replace TABMAG->Codice with "01010001"
Replace TABMAG->Desc with "Lcd 15"
TABMAG->(DbAppend())
Replace TABMAG->Chiave with "MERCE"
Replace TABMAG->Codice with "01010002"
Replace TABMAG->Desc with "Lcd 17"
TABMAG->(DbAppend())
Replace TABMAG->Chiave with "MERCE"
Replace TABMAG->Codice with "01010003"
Replace TABMAG->Desc with "Lcd 21"
TABMAG->(DbAppend())
Replace TABMAG->Chiave with "MERCE"
Replace TABMAG->Codice with "01010004"
Replace TABMAG->Desc with "Crt"
TABMAG->(DbAppend())
Replace TABMAG->Chiave with "MERCE"
Replace TABMAG->Codice with "0201"
Replace TABMAG->Desc with "Applications"
TABMAG->(DbAppend())
Replace TABMAG->Chiave with "MERCE"
Replace TABMAG->Codice with "02010001"
Replace TABMAG->Desc with "OFFICE"
TABMAG->(DbAppend())
Replace TABMAG->Chiave with "MERCE"
Replace TABMAG->Codice with "02010002"
Replace TABMAG->Desc with "FIVEWIN"
ENDIF
DbCloseAll()
return nil