Page 1 of 1

Xbrowse Tree using Array instead of DBF

Posted: Tue Dec 06, 2011 8:52 am
by fraxzi
Hi!

It's been a while since I posted but almost everyday I read topics here..

I usually do xbrowse tree using DBF data..

I couldn't find an example using Array data for an xbrowse tree.. anyone? .. Mr. RAO?


Kind Regards,
Frances

Re: Xbrowse Tree using Array instead of DBF

Posted: Tue Dec 06, 2011 10:33 am
by anserkk
Try this.
Image

Code: Select all

#include "FiveWin.ch"
#include "xBrowse.ch"
//---------------------//
Function Main()

    Local oBrw,oWnd
   
    DEFINE WINDOW oWnd TITLE "Tree using Array" 
    @0,0 XBROWSE oBrw OF oWnd 
    
    WITH OBJECT oBrw
      :SetTree(BuildTree())
      :oTree:OpenAll()
      :CreateFromCode()
    END
   
    oWnd:oClient:=oBrw
    ACTIVATE WINDOW oWnd
Return NIL 

//---------------------//
Function BuildTree()

    Local oTree,nTreeCount,nPrevLevel,nCurLevel,nLevelDiff
    Local i,j
    Local aItems:={ {"01","Computers"      ,0},;
                    {"02","Core i3"        ,1},;
                    {"03","Core i5"        ,1},;   
                    {"04","Furnitures"     ,0},;
                    {"05","Tables"         ,1},;   
                    {"06","Computer Table" ,2},;
                    {"07","Regular Table"  ,2},;                    
                    {"08","Desk"           ,1},;
                    {"09","Computer Desk"  ,2},;                    
                    {"10","Regular Desk"   ,2},;                    
                    {"11","Chairs"         ,1} }   
                    
    TREE oTree  
    nLevel:=aItems[1][3] 
    nTreeCount:=0             
    For i:=1 to Len(aItems)
        if aItems[i][3] > nLevel
            TREE
            nTreeCount++
        Elseif aItems[i][3] < nLevel
            nPrevLevel:=nLevel
            nCurLevel:=aItems[i][3] 
            nLevelDiff:=nPrevLevel-nCurLevel
            For j:=1 to nLevelDiff
                ENDTREE
                nTreeCount--
            Next
        Endif    
        TREEITEM aItems[i][2] CARGO { aItems[i][1] }  // Item Code
        nLevel:=aItems[i][3]
    Next               
    if nTreeCount > 0
       For i:=nTreeCount To 1 Step -1
          ENDTREE
       Next
    Endif        
    ENDTREE
Return oTree
Regards
Anser

Re: Xbrowse Tree using Array instead of DBF

Posted: Tue Dec 06, 2011 3:01 pm
by RAMESHBABU
Hello Anser,

Very Good Example :D

Regards,

- Ramesh

Re: Xbrowse Tree using Array instead of DBF

Posted: Wed Dec 07, 2011 12:04 am
by fraxzi
Hi Anser!

That's a good one!


Kind regards,
Frances

Re: Xbrowse Tree using Array instead of DBF

Posted: Tue Jul 24, 2012 9:58 pm
by ACC69
anserkk wrote:Try this.
Image

Code: Select all

#include "FiveWin.ch"
#include "xBrowse.ch"
//---------------------//
Function Main()

    Local oBrw,oWnd
   
    DEFINE WINDOW oWnd TITLE "Tree using Array" 
    @0,0 XBROWSE oBrw OF oWnd 
    
    WITH OBJECT oBrw
      :SetTree(BuildTree())
      :oTree:OpenAll()
      :CreateFromCode()
    END
   
    oWnd:oClient:=oBrw
    ACTIVATE WINDOW oWnd
Return NIL 

//---------------------//
Function BuildTree()

    Local oTree,nTreeCount,nPrevLevel,nCurLevel,nLevelDiff
    Local i,j
    Local aItems:={ {"01","Computers"      ,0},;
                    {"02","Core i3"        ,1},;
                    {"03","Core i5"        ,1},;   
                    {"04","Furnitures"     ,0},;
                    {"05","Tables"         ,1},;   
                    {"06","Computer Table" ,2},;
                    {"07","Regular Table"  ,2},;                    
                    {"08","Desk"           ,1},;
                    {"09","Computer Desk"  ,2},;                    
                    {"10","Regular Desk"   ,2},;                    
                    {"11","Chairs"         ,1} }   
                    
    TREE oTree  
    nLevel:=aItems[1][3] 
    nTreeCount:=0             
    For i:=1 to Len(aItems)
        if aItems[i][3] > nLevel
            TREE
            nTreeCount++
        Elseif aItems[i][3] < nLevel
            nPrevLevel:=nLevel
            nCurLevel:=aItems[i][3] 
            nLevelDiff:=nPrevLevel-nCurLevel
            For j:=1 to nLevelDiff
                ENDTREE
                nTreeCount--
            Next
        Endif    
        TREEITEM aItems[i][2] CARGO { aItems[i][1] }  // Item Code
        nLevel:=aItems[i][3]
    Next               
    if nTreeCount > 0
       For i:=nTreeCount To 1 Step -1
          ENDTREE
       Next
    Endif        
    ENDTREE
Return oTree
Regards
Anser

Hola buenas tardes Anserk,como esta, estoy tratando de compilar tu ejemplo, pero me marca error,que es lo que hace falta,uso version 8.12

//---------------------//
Function BUSCAR1()

Local oBrw,oWnd

DEFINE WINDOW oWnd TITLE "Tree using Array"
@0,0 XBROWSE oBrw OF oWnd

WITH OBJECT oBrw
:SetTree(BuildTree())
:oTree:OpenAll()
:CreateFromCode()
END

oWnd:oClient:=oBrw
ACTIVATE WINDOW oWnd
Return NIL

//---------------------//
Function BuildTree()

Local oTree,nTreeCount,nPrevLevel,nCurLevel,nLevelDiff
Local i,j,nLevel
Local aItems:={ {"01","Computers" ,0},;
{"02","Core i3" ,1},;
{"03","Core i5" ,1},;
{"04","Furnitures" ,0},;
{"05","Tables" ,1},;
{"06","Computer Table" ,2},;
{"07","Regular Table" ,2},;
{"08","Desk" ,1},;
{"09","Computer Desk" ,2},;
{"10","Regular Desk" ,2},;
{"11","Chairs" ,1} }

TREE oTree
nLevel:=aItems[1][3]
nTreeCount:=0
For i:=1 to Len(aItems)
if aItems[3] > nLevel
TREE
nTreeCount++
Elseif aItems[3] < nLevel
nPrevLevel:=nLevel
nCurLevel:=aItems[3]
nLevelDiff:=nPrevLevel-nCurLevel
For j:=1 to nLevelDiff
ENDTREE
nTreeCount--
Next
Endif
TREEITEM aItems[2] CARGO { aItems[1] } // Item Code
nLevel:=aItems[3]
Next
if nTreeCount > 0
For i:=nTreeCount To 1 Step -1
ENDTREE
Next
Endif
ENDTREE
Return oTree

Este es el error :

C:\Pro_FWH\ProveIVA\Prg\buscar1.prg(70) Error E0030 Syntax error: "syntax
error at 'AITEMS'"

Estoy tratando de adaptar a mi catalago de cuentas de 1 a 4 niveles de cuentas con caracter y longitud 16 ,y estaba tomando tu ejemplo, pero no me sale desde mi dbfs.

Saludos y buen dia.

Atte: Adrian C. C.

Re: Xbrowse Tree using Array instead of DBF

Posted: Wed Jul 25, 2012 7:01 am
by anserkk
Sorry,
I cannot find line 70 in your code. As per your message, the error occurs at line 70. The max no of lines in the code posted by you is only 61.

Did you try the sample code posted by me on your PC using your FHW ver 8.12 ?. Did it work ?

Regards
Anser

Re: Xbrowse Tree using Array instead of DBF

Posted: Wed Jul 25, 2012 2:02 pm
by ACC69
anserkk wrote:Sorry,
I cannot find line 70 in your code. As per your message, the error occurs at line 70. The max no of lines in the code posted by you is only 61.

Did you try the sample code posted by me on your PC using your FHW ver 8.12 ?. Did it work ?

Regards
Anser
Hola buenos dias de nuevo, el error se produce aqui en esta linea ....

For i:=1 to Len(aItems)
if aItems[3] > nLevel
TREE
nTreeCount++
Elseif aItems[3] < nLevel
nPrevLevel:=nLevel
nCurLevel:=aItems[3]
nLevelDiff:=nPrevLevel-nCurLevel
For j:=1 to nLevelDiff
ENDTREE
nTreeCount--
Next
Endif
TREEITEM aItems[2] CARGO { aItems[1] } // Item Code /// Anserk aqui se me produce este error, y es con tu codigo que estoy probando....
nLevel:=aItems[3]
Next

Quiero implementar mi catalogo de cuentas en forma de tree,mi estructura en la base de datos es asi : Cuentas caracter longitud 16 y nivel longitud 1 numerico

CUENTAS NIVEL DESCRIPCION

1020-0000-0000-0000 1 Cuenta mayor
1020-0001-0000-0000 2 Subcta
1020-0001-0001-0000 3 Subsubcta
1020-0001-0001-0001 4 subsubctanddetalles

Pero como hacerle con tu ejemplo, que intento compilar, pero ese error me sigue dando, y es el mismo ejemplo con tu codigo, solo le agregue la variable nLevel, que no estaba declarado,uso VERCE 5.0 y FWH 8.12

Saludos y buen dia Anserk

Atte: Adrian C. C.

Re: Xbrowse Tree using Array instead of DBF

Posted: Wed Jul 25, 2012 2:48 pm
by Otto
I use normal xBrowse with

oBrw:bIndent := { ||20 + ( ::cAlias )->TREELEVEL * 20 }

instead of treeView.

Best regards,
Otto

Image

Re: Xbrowse Tree using Array instead of DBF

Posted: Thu Jul 26, 2012 4:55 am
by anserkk
To do a test with your FWH ver, I don't have FWH 8.12 here with me right now.

Many changes has been implemented to Tree after Ver 8.12

Anyway Tree with your data is working fine here with the latest FWH version.

CUENTAS NIVEL DESCRIPCION
1020-0000-0000-0000 1 Cuenta mayor
1020-0001-0000-0000 2 Subcta
1020-0001-0001-0000 3 Subsubcta
1020-0001-0001-0001 4 subsubctanddetalles

Image

Code: Select all

#include "FiveWin.ch"
#include "xBrowse.ch"
//---------------------//
Function Main()

    Local oBrw,oWnd
   
    DEFINE WINDOW oWnd TITLE "Tree using Array"
    @0,0 XBROWSE oBrw OF oWnd
   
    WITH OBJECT oBrw
      :SetTree(BuildTree())
      :oTree:OpenAll()
      :CreateFromCode()
    END
   
    oWnd:oClient:=oBrw
    ACTIVATE WINDOW oWnd
Return NIL

//---------------------//
Function BuildTree()

    Local oTree,nTreeCount,nPrevLevel,nCurLevel,nLevelDiff
    Local i,j
/*    Local aItems:={ {"01","Computers"      ,0},;
                    {"02","Core i3"        ,1},;
                    {"03","Core i5"        ,1},;  
                    {"04","Furnitures"     ,0},;
                    {"05","Tables"         ,1},;  
                    {"06","Computer Table" ,2},;
                    {"07","Regular Table"  ,2},;                    
                    {"08","Desk"           ,1},;
                    {"09","Computer Desk"  ,2},;                    
                    {"10","Regular Desk"   ,2},;                    
                    {"11","Chairs"         ,1} }  
*/                    
Local aItems:={ {"1020-0000-0000-0000", 1,"Cuenta mayor"},;
                {"1020-0001-0000-0000", 2,"Subcta"},;
                {"1020-0001-0001-0000", 3,"Subsubcta"},;
                {"1020-0001-0001-0001", 4,"subsubctanddetalles"} }                    
                   
    TREE oTree  
    nLevel:=aItems[1][2]
    nTreeCount:=0            
    For i:=1 to Len(aItems)
        if aItems[i][2] > nLevel
            TREE
            nTreeCount++
        Elseif aItems[i][2] < nLevel
            nPrevLevel:=nLevel
            nCurLevel:=aItems[i][2]
            nLevelDiff:=nPrevLevel-nCurLevel
            For j:=1 to nLevelDiff
                ENDTREE
                nTreeCount--
            Next
        Endif    
        TREEITEM aItems[i][3] CARGO { aItems[i][1] }  // Item Code
        nLevel:=aItems[i][2]
    Next              
    if nTreeCount > 0
       For i:=nTreeCount To 1 Step -1
          ENDTREE
       Next
    Endif        
    ENDTREE
Return oTree
Regards
Anser

Re: Xbrowse Tree using Array instead of DBF

Posted: Thu Jul 26, 2012 4:02 pm
by ACC69
anserkk wrote:To do a test with your FWH ver, I don't have FWH 8.12 here with me right now.

Many changes has been implemented to Tree after Ver 8.12

Anyway Tree with your data is working fine here with the latest FWH version.

CUENTAS NIVEL DESCRIPCION
1020-0000-0000-0000 1 Cuenta mayor
1020-0001-0000-0000 2 Subcta
1020-0001-0001-0000 3 Subsubcta
1020-0001-0001-0001 4 subsubctanddetalles

Image

Code: Select all

#include "FiveWin.ch"
#include "xBrowse.ch"
//---------------------//
Function Main()

    Local oBrw,oWnd
   
    DEFINE WINDOW oWnd TITLE "Tree using Array"
    @0,0 XBROWSE oBrw OF oWnd
   
    WITH OBJECT oBrw
      :SetTree(BuildTree())
      :oTree:OpenAll()
      :CreateFromCode()
    END
   
    oWnd:oClient:=oBrw
    ACTIVATE WINDOW oWnd
Return NIL

//---------------------//
Function BuildTree()

    Local oTree,nTreeCount,nPrevLevel,nCurLevel,nLevelDiff
    Local i,j
/*    Local aItems:={ {"01","Computers"      ,0},;
                    {"02","Core i3"        ,1},;
                    {"03","Core i5"        ,1},;  
                    {"04","Furnitures"     ,0},;
                    {"05","Tables"         ,1},;  
                    {"06","Computer Table" ,2},;
                    {"07","Regular Table"  ,2},;                    
                    {"08","Desk"           ,1},;
                    {"09","Computer Desk"  ,2},;                    
                    {"10","Regular Desk"   ,2},;                    
                    {"11","Chairs"         ,1} }  
*/                    
Local aItems:={ {"1020-0000-0000-0000", 1,"Cuenta mayor"},;
                {"1020-0001-0000-0000", 2,"Subcta"},;
                {"1020-0001-0001-0000", 3,"Subsubcta"},;
                {"1020-0001-0001-0001", 4,"subsubctanddetalles"} }                    
                   
    TREE oTree  
    nLevel:=aItems[1][2]
    nTreeCount:=0            
    For i:=1 to Len(aItems)
        if aItems[i][2] > nLevel
            TREE
            nTreeCount++
        Elseif aItems[i][2] < nLevel
            nPrevLevel:=nLevel
            nCurLevel:=aItems[i][2]
            nLevelDiff:=nPrevLevel-nCurLevel
            For j:=1 to nLevelDiff
                ENDTREE
                nTreeCount--
            Next
        Endif    
        TREEITEM aItems[i][3] CARGO { aItems[i][1] }  // Item Code
        nLevel:=aItems[i][2]
    Next              
    if nTreeCount > 0
       For i:=nTreeCount To 1 Step -1
          ENDTREE
       Next
    Endif        
    ENDTREE
Return oTree
Regards
Anser

Gracias Anserk, yo creo que si tienes razon, ha de ser mi version, porque hasta la variable nLevel, la tuve que definir ,porque no me la reconocia,le preguntare a Antonio LInares, con cual podria sustituir la variable aItems, para mi version 8.12., o hay otra manera de crear para ese modulo que me esta dando vueltas la cabeza, con mi arbol de catalogo de cuentas.

Gracias de todos modos y un saludos

Atte: Adrian C. C.

Re: Xbrowse Tree using Array instead of DBF

Posted: Thu Jul 26, 2012 5:23 pm
by Eoeo
and if I wish insert a check for each item how I can make ?

for a sample I have a menu items and I wish show any items instead of others

Re: Xbrowse Tree using Array instead of DBF

Posted: Thu Jul 26, 2012 5:39 pm
by Otto
Silvio,
try to use oBrw:bIndent.

Best regards,
Otto
Image

Re: Xbrowse Tree using Array instead of DBF

Posted: Thu Jul 26, 2012 8:05 pm
by Eoeo
where ? can you modify the test made from Anserkk please ?
or made another

I use an array to create ribbon

aMenuRibbon := { "Gestione Ufficio Tecnico","Hardware","Software","Manuali","Prestiti","Magazzino","Utilità","Aiuto" }
::obar:=TRibbonBar():New(::oWndMain, aMenuRibbon,,,,140,25,,,,,,,,,,.F.,1 )

we can create a configuration to set wich menu we not want to show....