Converte oTree into Xbrowse Tree

Converte oTree into Xbrowse Tree

Postby Silvio.Falconi » Thu Jan 19, 2023 11:36 am

I wish converte a Tree into xbrowse tree for a sample a I must converte the buildtree
the Dbf have two Field GeMateria, GepClave all to 40/45 Cr

Image


Code: Select all  Expand view
function BuildTree( oTree,nTipo )
   local oLink1, oLink2

   DEFAULT  ntipo := 1

  SELECT GE
   GE->(DbGoTop())
   IF ntipo=1
      DO WHILE ! GE->(EOF())
        if Rtrim(GE->GEPClave) == ""
         oLink1 := oTree:Add(GE->GEMATERIA,0)
         oLink1:Cargo := Upper(GE->GEMATERIA)
         oTree:Cargo  := GE->GEMATERIA
     else
         oLink2 := oLink1:Add(GE->GEPClave,1)
         oLink2:Cargo := Upper(GE->GEMATERIA) + Upper(GE->GEPClave)
      endif
      GE->(DbSkip())
   ENDDO


elseif ntipo=2

   DO WHILE ! GE->(EOF())
       if Rtrim(GE->GEPClave) == ""
            oLink1 := oTree:Add(GE->GEMATERIA,0)
         oLink1:Cargo := Upper(GE->GEMATERIA)
         oTree:Cargo  := GE->GEMATERIA
         Endif
         GE->(DbSkip())
       ENDDO
   Endif
   oTree:SetFocus()
   return nil
 


How Converte to xbrowse tree , any solution ?


I made this ( ad the sample test xbrwtree.prg)

Code: Select all  Expand view

#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()

   local oWnd, oBrw

   CreateSampleDbf()

   USE GRUENT ALIAS GE
   INDEX ON UPPER(GE->GEMATERIA)+UPPER(GE->GEPCLAVE) TAG GE01 FOR !Deleted()
   INDEX ON UPPER(GE->GEMATERIA) TAG GE02  FOR   ((!DELETED()) )
   INDEX ON UPPER(GE->GEPCLAVE) TAG GE03  FOR   ((!DELETED()) )
   GE->(DbSetOrder(1))


   DEFINE WINDOW oWnd TITLE " 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 "Categoria"
   ADD TO oBrw DATA oBrw:oTreeItem:Cargo[ 2 ] HEADER "Sottocategoria"

   oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW

   oBrw:CreateFromCode()
   oBrw:aCols[ 1 ]:cHeader = "Categoria"

   oWnd:oClient = oBrw

   ACTIVATE WINDOW oWnd

return nil

static function BuildTree()

   local oTree, cState

   TREE oTree
      while ! Eof()
         if Empty( cState )
            _TreeItem( GE->GEMATERIA ):Cargo := { Space( 20 ), Space( 20 ) }
            TREE
            cState = GE->GEMATERIA
         else
            if cState != GE->GEMATERIA
               ENDTREE
               cState = GE->GEMATERIA
               _TreeItem( GE->GEMATERIA ):Cargo := { Space( 20 ), Space( 20 ) }
               TREE
            endif
         endif
         if GE->GEMATERIA == cState
            _TreeItem( GE->GEPCLAVE ):Cargo := { GE->GEMATERIA, GE->GEPCLAVE }
         endif
         SKIP
      enddo
      ENDTREE
   ENDTREE

   GO TOP

   return oTree





   Function CreateSampleDbf()


    DbCreate('GE', {{'GEMATERIA'  , 'C',   40,   0} ,;
                    {'GEPCLAVE' , 'C',   45,   0} ,;
                    {'MAEJEMPL' , 'N',    5,   0}}, 'DBFCDX')

      close all
      use &('GE') new
      select GE
      if FILE('GRUENT.DBF')
         delete file &('GRUENT.cdx')
         append from &('GRUENT')
         dbcommitall()
         close all
         delete file &('GRUENT.dbf')

      endif
      close all
      rename &('GE.dbf') to &('GRUENT.dbf')

   return nil










 


But not run as I wanted

I have this

Image



But where is the other categories ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: Converte oTree into Xbrowse Tree

Postby Silvio.Falconi » Fri Jan 20, 2023 8:26 am

Now I corrected with

Code: Select all  Expand view

#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()

   local oWnd, oBrw

   CreateSampleDbf()

   USE GRUENT ALIAS GE
   INDEX ON UPPER(GE->GEMATERIA)+UPPER(GE->GEPCLAVE) TAG GE01 FOR !Deleted()
   INDEX ON UPPER(GE->GEMATERIA) TAG GE02  FOR   ((!DELETED()) )
   INDEX ON UPPER(GE->GEPCLAVE) TAG GE03  FOR   ((!DELETED()) )
   GE->(DbSetOrder(1))


   DEFINE WINDOW oWnd TITLE " 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 "Sottocategoria"

   oBrw:nMarqueeStyle = MARQSTYLE_HIGHLROW

   oBrw:CreateFromCode()
   oBrw:aCols[ 1 ]:cHeader = "Categoria"

   oWnd:oClient = oBrw

   ACTIVATE WINDOW oWnd

return nil
 static function BuildTree(nTipo)
local oTree, cState
  SELECT GE
  GE->(DbGoTop())
     TREE oTree
   do while !GE->(EOF())
      if Empty( GE->GEPClave )
        GE->(DbSkip())
      else
         TREEITEM GE->GEMATERIA CARGO { space(40) }
         cname    := GE->GEMATERIA
         TREE
         do while GE->GEMATERIA == cname .and. !GE->(EOF())
            TREEITEM GE->GEMATERIA CARGO { GE->GEPClave }
          GE->(DbSkip())
         enddo
         ENDTREE
      endif
   enddo
   ENDTREE
 return oTree
 Function CreateSampleDbf()


    DbCreate('GE', {{'GEMATERIA'  , 'C',   40,   0} ,;
                    {'GEPCLAVE' , 'C',   45,   0} ,;
                    {'MAEJEMPL' , 'N',    5,   0}}, 'DBFCDX')

      close all
      use &('GE') new
      select GE
      if FILE('GRUENT.DBF')
         delete file &('GRUENT.cdx')
         append from &('GRUENT')
         dbcommitall()
         close all
         delete file &('GRUENT.dbf')

      endif
      close all
      rename &('GE.dbf') to &('GRUENT.dbf')

   return ni



Result

Image


It seems run ok, only when I select a category show on first column the category and I wish show blank...
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: Converte oTree into Xbrowse Tree

Postby Silvio.Falconi » Fri Jan 20, 2023 8:44 am

Ok Now run ok
Code: Select all  Expand view
static function BuildTree(nTipo)
local oTree, cState
  SELECT GE
  GE->(DbGoTop())
     TREE oTree
   do while !GE->(EOF())
      if Empty( GE->GEPClave )
        GE->(DbSkip())
      else
         TREEITEM GE->GEMATERIA CARGO { space(40) }
         cState    := GE->GEMATERIA
         TREE
         do while GE->GEMATERIA == cState .and. !GE->(EOF())
            TREEITEM "" CARGO { GE->GEPClave }  //GE->GEMATERIA
          GE->(DbSkip())
         enddo
         ENDTREE
      endif
   enddo
   ENDTREE
   return oTree


Image



How I can to converte these commands :
oTree:ExpandAll()
oTree:CollapseAll()
oTree:ExpandBranch()
oTree:CollapseBranch()
oTree:GetSelected() I need it for edit/modify
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 71 guests