xbrowse <-> Tree and viceversa

xbrowse <-> Tree and viceversa

Postby Silvio.Falconi » Sat May 13, 2023 9:43 am

I have the customer.dbf table,

Image



and above the table I can do a search then a get and a combox

I would like to make groupings for example for the State field, so I could use an Xbrowse Tree control and create the same columns you see in the picture.

But I would also like the end user to be able to select the grouping via a popup menu above the dialog .
the end user can select to do the grouping by the "State" field or not to do it.

If it decides not to do the grouping the procedure has to go back to the initial table

That is, I would like to show both a normal table ( xbrowse) and a tree ( xbrowse) in the same xbrowse.

if i have a tree how can i make the lookup work the same as i do with the regular table?

how could i do it?


I made a test but not run ok see the video


Image
Last edited by Silvio.Falconi on Tue May 16, 2023 7:05 am, edited 1 time in total.
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: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: xbrowse <-> Tree and viceversa

Postby reinaldocrespo » Sat May 13, 2023 4:08 pm

Hello Silvio;

Your images don't show when I browse but regardless, I think I understand what you're looking for and want to suggest a way to get it.

1. Declare a regular xbrowse on a dialog and also another xbrowse hosting an otree with the very same data source on another dialog.
2. Have both occupy the very same area.
3. When you want to show the regular browse, show that dialog and hide the other and vise versa.
4. When you make changes on one, just make sure to refresh both.

Being that both xbrowses occupy the very same real estate on the screen. only one of the two will be visible at a time.

I hope that helps,
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: xbrowse <-> Tree and viceversa

Postby Silvio.Falconi » Sat May 13, 2023 5:09 pm

the problem is that i use a scheme ie i use xbrowse search with a get and a combobox, and also the multiselect . When I create the tree it could also work but the search doesn't work

I really don't think I have to use two separate dialogs, the dialog and the xbrowse must be the same, I created something that doesn't work but I'm sure nages will find the solution. It is important to have a grouping, for example in an archive of articles we can view the normal table or a grouping by category, it must be a fluid system. Must have research in both situations

see your mail.
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: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: xbrowse <-> Tree and viceversa

Postby reinaldocrespo » Sun May 14, 2023 5:56 pm

Yes, obrw search probably wont work for searching but if that is the problem, then perhaps something like this extended cb is the idea you are looking for:

Code: Select all  Expand view
  ::bSearch := ;
   < | isFromStart, isJump |  
      LOCAL isFound := .F.
      LOCAL oBranch := IIF( isFromStart, ::oBrw:oTree:oFirst, ::oBrw:oTreeItem )
     
      DEFAULT isJump := .T.

      WHILE oBranch != NIL .AND. ;
            !( isFound := ALLTRIM( oBranch:cPrompt ) == ::cSeek ) .AND. ;
            !( isFound := ALLTRIM( oBranch:Cargo[ _ADMNUM ] ) == ::cSeek ) .AND. ;
            !( isFound := UPPER( ALLTRIM( ::cSeek ) ) $ UPPER( oBranch:Cargo[ _PATNAME ] ) )
           
         oBranch := oBranch:GetNext()

      END

      IF isFound .AND. isJump  ;EVAL( ::oBrw:bBookmark, oBranch:ItemNo() )  ;ENDIF
   
      RETURN isFound
   >
 


This code searches on various columns of the xbrowse tree. Change to search on more columns or just 1 column by adjusting _ADMNUM and _PTENAME to column index you want to search on.

Hope it helps or at least points towards the solution you are looking for.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: xbrowse <-> Tree and viceversa

Postby Otto » Sun May 14, 2023 8:49 pm

Hello Silvio,

I asked ChatGPT:
I pass the Fivewin documentation along with my question.
Best regards,
Otto

Code: Select all  Expand view

To achieve the desired functionality of displaying both a regular table (xBrowse) and a tree (xBrowse) in the same xBrowse control with the ability to switch between grouping and non-grouping modes, you can follow these steps:

Create the xBrowse control and attach the initial table (customer.dbf) as the data source using the SetRDD() method.

Define the columns for the regular table view of the xBrowse. You can use the AddColumn() method to add columns with field names or expressions, similar to how you would define columns for a regular xBrowse.

Implement the grouping functionality using an xBrowse Tree control. You can create a separate xBrowse Tree control and attach it as a child of the main xBrowse control. Configure the xBrowse Tree control to display the grouped data based on the "State" field.

Implement the popup menu above the dialog to allow the end user to select the grouping option. When the user selects the grouping option, switch the xBrowse control to display the xBrowse Tree control with the grouped data.

Handle the scenario when the user decides not to do grouping. In this case, you need to switch the xBrowse control back to display the regular table view. You can achieve this by hiding or removing the xBrowse Tree control and reattaching the initial table as the data source using the SetRDD() method.

To make the lookup work the same as with the regular table, you can handle the lookup functionality separately for the regular table view and the grouped view (xBrowse Tree control). When the xBrowse control is displaying the regular table view, you can handle the lookup functionality as you normally would for a regular xBrowse. When the xBrowse control is displaying the grouped view, you can implement custom lookup functionality specific to the grouped data structure, such as searching within the grouped nodes or expanding/collapsing the nodes to perform the lookup.

By combining these steps, you can create an xBrowse control that can display both a regular table view and a grouped view using an xBrowse Tree control, allowing the end user to switch between the two and perform lookups in a consistent manner.





 
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Re: xbrowse <-> Tree and viceversa

Postby Silvio.Falconi » Sun May 14, 2023 10:16 pm

I sent to fwteam a test. It can runn but the search run only with normale xbrowse and not with xbrowse tree
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: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: xbrowse <-> Tree and viceversa

Postby cnavarro » Mon May 15, 2023 12:07 am

Silvio.Falconi wrote:I sent to fwteam a test. It can runn but the search run only with normale xbrowse and not with xbrowse tree

Dear Silvio
To use Tree or normal view in an xbrowse, you have an example in xbrtree.prg ( samples folder).
Allow to search in the tree as in the normal xbrowse, with what criteria? I don't understand that you can search, for example, for a surname that can be in several groups of the tree, that is, the table cannot be sorted at that moment because the tree would be lost.
If a custom search is set (manually), I understand it can be done.
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6541
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: xbrowse <-> Tree and viceversa

Postby reinaldocrespo » Mon May 15, 2023 3:53 pm

Otto, I'm really impressed with the answer. It opens our minds.

I wonder if you can follow up that same chat and ask to write sample code that implements those steps and then compare to how close to working code it produces.
User avatar
reinaldocrespo
 
Posts: 979
Joined: Thu Nov 17, 2005 5:49 pm
Location: Fort Lauderdale, FL

Re: xbrowse <-> Tree and viceversa

Postby Silvio.Falconi » Tue May 16, 2023 7:09 am

Otto wrote:Hello Silvio,

I asked ChatGPT:
I pass the Fivewin documentation along with my question.
Best regards,
Otto

Code: Select all  Expand view

To achieve the desired functionality of displaying both a regular table (xBrowse) and a tree (xBrowse) in the same xBrowse control with the ability to switch between grouping and non-grouping modes, you can follow these steps:

Create the xBrowse control and attach the initial table (customer.dbf) as the data source using the SetRDD() method.

Define the columns for the regular table view of the xBrowse. You can use the AddColumn() method to add columns with field names or expressions, similar to how you would define columns for a regular xBrowse.

Implement the grouping functionality using an xBrowse Tree control. You can create a separate xBrowse Tree control and attach it as a child of the main xBrowse control. Configure the xBrowse Tree control to display the grouped data based on the "State" field.

Implement the popup menu above the dialog to allow the end user to select the grouping option. When the user selects the grouping option, switch the xBrowse control to display the xBrowse Tree control with the grouped data.

Handle the scenario when the user decides not to do grouping. In this case, you need to switch the xBrowse control back to display the regular table view. You can achieve this by hiding or removing the xBrowse Tree control and reattaching the initial table as the data source using the SetRDD() method.

To make the lookup work the same as with the regular table, you can handle the lookup functionality separately for the regular table view and the grouped view (xBrowse Tree control). When the xBrowse control is displaying the regular table view, you can handle the lookup functionality as you normally would for a regular xBrowse. When the xBrowse control is displaying the grouped view, you can implement custom lookup functionality specific to the grouped data structure, such as searching within the grouped nodes or expanding/collapsing the nodes to perform the lookup.

By combining these steps, you can create an xBrowse control that can display both a regular table view and a grouped view using an xBrowse Tree control, allowing the end user to switch between the two and perform lookups in a consistent manner.





 


aside I don't think chatGpt knows fivewin and Harbor because I've already tried a thousand times and I haven't succeeded, if he replies to you why don't you try to ask this:
"Please create me a little Harbor/fivewin language program that does a xbrowse tree with grouping to one field and a normal xbrowse in the same xbrowse and creates record lookup"
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: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: xbrowse <-> Tree and viceversa

Postby Otto » Tue May 16, 2023 7:46 am

Silvio,

You need to include the Fivewin documentation along with your question as a knowledge base.

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Re: xbrowse <-> Tree and viceversa

Postby Silvio.Falconi » Tue May 16, 2023 7:49 am

this is a small test
the search not run
I used array

Code: Select all  Expand view

#include "fivewin.ch"

REQUEST DBFCDX

static lTipo1:=.f.,ltipo2:=.f.
//----------------------------------------------------------------------------//

function Main()

   local aData

   FERASE( "CUSTOMER.CDX" )
   USE CUSTOMER NEW EXCLUSIVE VIA "DBFCDX"
   aData := FW_DbfToArray( "FIRST,LAST,STREET,STATE", , { || RECNO() < 11 } )
   GO TOP
   FW_CdxCreate()
   CLOSE CUSTOMER

  Customers(aData)

return nil

//----------------------------------------------------------------------------//


function Customers(aData)

   local oDlg, oBrw, oGroup

   local oSay:=array(2)
   local cSeek:=Space(100)
   local oGet

   DEFINE DIALOG oDlg SIZE 800,400 PIXEL TRUEPIXEL RESIZABLE

   @ 10, 165 GET oGet VAR cSeek SIZE 200,19 PIXEL OF oDlg PICTURE "@!"


   /*  @ nRow - 1, 10 COMBOBOX nFilter SIZE 60, If( IsAppThemed(), 14, 60 ) PIXEL OF oDlg ;
         ITEMS { "Search For", "Show Only" } ;
         ON CHANGE ( oBrw:Seek( "" ), oBrw:lIncrFilter := nFilter > 1,  oBrw:SetFocus() )

      @ nRow - 1, 72 COMBOBOX nSeekWild ;
         size 60, If( IsAppThemed(), 14, 60 ) pixel of oDlg ;
         ITEMS { "Starting With", "Containing" } ;
         on change ( oBrw:lSeekWild := ( nSeekWild > 1 ), oBrw:Seek( "" ), oBrw:SetFocus() )
      */




    @ 10, 700  BTNBMP oGroup Prompt "group on" ;
                FLAT  SIZE 80, 20  OF oDlg   PIXEL ;
                BITMAP ".\bitmaps\combo.bmp" RIGHT NOROUND;
           ACTION  ::ShowPopUp( { |oBtn| BtnPop( aData, oDlg, oBrw,oGet ) } )

   ACTIVATE DIALOG oDlg CENTERED;
            on init oBrw:= MyBrowse(aData,oDlg, oBrw)

return nil
//--------------------------------------------------------------------------------//
Function MyBrowse(aData,oDlg, oBrw, oGet)


 @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE aData ;
      AUTOCOLS ;
      HEADERS "NAME","SURNAME","ADDRESS","STATE" ;
      AUTOSORT ;
      NOBORDER LINES

   WITH OBJECT oBrw

       :lHScroll  := .f.
       :SetMultiSelectCol()
      //---
            :lIncrFilter      := .t.
            :bOnSort          := { |b,oCol| oBrw:Seek( "" ), ;
                                   oBrw:cFilterFld := oCol:cExpr, ;
                                   oBrw:SetFocus() }
            :oSeek := oGet
            //----
      :CreateFromCode()
   END


   @ 10,20 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder SIZE 100,400 PIXEL OF oDlg

return oBrw
//--------------------------------------------------------------------------------//

Function BtnPop(aData, oDlg, oBrw,oGet)
local oItem1,oItem2
MENU oMenu POPUP
MENUITEM oItem1 PROMPT "State" ;
ACTION (lTipo1 := !lTipo1,;
       ( Iif( ltipo1,MakeGroup(oBrw,oGet,oDlg),;
                     MyBrowse(aData,oDlg, oBrw,oGet) )))
oItem1:SetCheck(lTipo1)
ENDMENU
return oMenu
//---------------------------------------------------------------------//


Function  MakeGroup(oBrw,oGet,oDlg)  // simulation
   local aDatatree:={}
   local aState:={}
   local cState :=""
   local n:= 1
   local k
   local aHeaders:=  { "First","Last","City","State"}
   local oCol
   local oDbf

   oDbf:=Tdatabase():Open(,"customer" ,"DBFCDX", .t.)
   oDbf:setorder("state")
   oDbf:gotop()


    //load State
     Do while .not.  oDbf:eof()
        IF !Empty(oDbf:state) .and. oDbf:State!=cState
           aadd(aState,oDbf:State)
           n++
        Endif
        cState:= oDbf:State
        oDbf:skip()
     Enddo
      oDbf:gotop()



  // see on dbf for state
  k:= 0
    For n= 1 to len( astate)
        k:=k+1
       aadd(aDatatree,{"State"+chr(187)+aState[n] ,"","","",k } )
        oDbf:Seek(aState[n])
        Do while !oDbf:Eof()
           if alltrim(oDbf:state) == alltrim(astate[n])
              k:=k+1
             aadd(aDatatree,{space(20)+alltrim(oDbf:First),oDbf:Last,oDbf:city,oDbf:state,k } )
             else
             exit
             Endif
             oDbf:skip()
          enddo
           oDbf:gotop()
        Next
        oDbf:close()

          // make a sort
        aDatatree   := aSort( aDatatree,,,{|x,y| (x[5]) < (y[5])})

          // insert on xbrowse
         oBrw:ResetData( nil,{} )
         oBrw:lAutoSort := .t.


         oBrw:setarray(aDatatree)

         // set the titles

             oBrw:aCols[ 1 ]:cHeader := "State"
             oBrw:aCols[ 2 ]:cHeader := "First"
             oBrw:aCols[ 3 ]:cHeader  := "Last"
             oBrw:aCols[ 4 ]:cHeader  := "Last"
             oBrw:aCols[ 5 ]:cHeader  := "State"

         // hide :aCols[5]  the number I used
         oBrw:aCols[5]:Hide()


         //these not run
         oBrw:lIncrFilter      := .t.
         oBrw:lSeekWild          := .t.
            oBrw:bOnSort          := { |b,oCol| oBrw:Seek( "" ), ;
                                   oBrw:cFilterFld := oCol:cExpr, ;
                                   oBrw:SetFocus() }
            oBrw:oSeek := oGet


            // refresh()
            oBrw:refresh()

     return nil
//-------------------------------------------------------------------------------------------------------------//


 
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: 7052
Joined: Thu Oct 18, 2012 7:17 pm

Re: xbrowse <-> Tree and viceversa

Postby Otto » Tue May 16, 2023 8:37 am

Hello Silvio,
I get an anwer but I have an older version installed where things are missing.
Which version of FW do you use.
Best regards,
Otto
ChatGPT says:
The bOnSort property is defined as a code block, but its implementation is missing in the provided code. You need to define the sorting logic inside this code block to make the sorting functionality work.

In the MakeGroup function, there is a line oDbf:close(), which is closing the database file before performing operations on it. Remove this line to ensure the database file remains open for further operations.
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6328
Joined: Fri Oct 07, 2005 7:07 pm

Re: xbrowse <-> Tree and viceversa

Postby Silvio.Falconi » Tue May 16, 2023 10:07 am

Otto wrote:Hello Silvio,
I get an anwer but I have an older version installed where things are missing.
Which version of FW do you use.
Best regards,
Otto
ChatGPT says:
The bOnSort property is defined as a code block, but its implementation is missing in the provided code. You need to define the sorting logic inside this code block to make the sorting functionality work.

In the MakeGroup function, there is a line oDbf:close(), which is closing the database file before performing operations on it. Remove this line to ensure the database file remains open for further operations.


fwh release December 2021 to March 2022

I must close the oDbf with oDbf:close() I create an array aDatatree for xbrowse tree , why I need oDbf ?

I regularly use this scheme to do database lookups in all my dialogs

Code: Select all  Expand view


 @ 10, 165 GET oGet VAR cSeek SIZE 200,19 PIXEL OF oDlg PICTURE "@!"
 
@ 110,10 XBROWSE oBrw....

 WITH OBJECT oBrw
              :lHScroll  := .f.
            :lIncrFilter      := .t.
            :bOnSort          := { |b,oCol| oBrw:Seek( "" ), ;
                                   oBrw:cFilterFld := oCol:cExpr, ;
                                   oBrw:SetFocus() }
            :oSeek := oGet
            :CreateFromCode()
         END

 @ 10, 550 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder;
        SIZE 200,400 PIXEL OF oDlg

 
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: 7052
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 55 guests