Reload data in a combobox

Reload data in a combobox

Postby Silvio.Falconi » Tue Apr 30, 2024 8:03 am

I have an archive of categories and the subcategories are inserted in the same archive
I have to do a combobox check where I select the major categories and then I have to refresh another combobox with the lower categories corresponding to the major category selected.

when I go to reload the lower categories in the second combobox control it gives me an error

this is the test

Code: Select all  Expand view  RUN
#include "FiveWin.ch"
#include "Constant.ch"

request dbfcdx

Function test_reload_combo()
      local nBottom:= 22    
      local nRight := 55
      local nHt       := nBottom * DLG_CHARPIX_H
      local nWd       := Max( nRight * DLG_CHARPIX_W, 180 )
      local aget:=array(10)
      local oSay:=array(10)
      local oFont,oBold
      local nMode:= 1,n

       local aCategorie:=TCategorie():GetList()
      local aSubCategorie:={{"","nessuna"}}
       local cCategoria    := aCategorie[ 1 ][2]
       local cSubCategoria,npos



   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-12
   DEFINE FONT oBold NAME "TAHOMA" SIZE 0,-12  BOLD
   DEFINE DIALOG oDlg SIZE nWd, nHt PIXEL TRUEPIXEL;
   TITLE "test"


@  10,    10   SAY oSay[5] PROMPT  "categoria" SIZE 150,25  PIXEL OF oDlg  TRANSPARENT  FONT oFont
@ 10, 150 COMBOBOX aGet[5] VAR cCategoria Items ArrTranspose(aCategorie )[ 2]  size 240,120 PIXEL OF  oDlg FONT oFont HEIGHTGET 20 ;
       ON CHANGE  (  n:=aGet[5]:nat, ReloadCombo(@aSubCategorie,cCategoria, aCategorie[n][1] ),;
                 oSay[6]:show(),;
                 aget[6]:show(),;
                 aGet[6]:setItems(aSubCategorie),;
                 If(nMode==1,aGet[6]:Select( 1 ),;
                    ( nPos := AAT( aSubCategorie, cCategoria),aGet[5]:Select( nPos ))),;
                 aGet[5]:refresh())



 @  60,    10   SAY oSay[6] PROMPT  "Sottocategoria" SIZE 150,25  PIXEL OF oDlg  TRANSPARENT  FONT oFont
 @ 60, 150 COMBOBOX aget[6] VAR cSubCategoria Items  ArrTranspose(aSubCategorie )[ 2]  size 240,90 PIXEL OF  oDlg   HEIGHTGET 20


ACTIVATE DIALOG oDLG  CENTERED;
 ON INIT (oSay[6]:hide(),aget[6]:hide())

RETURN NIL


Function Categorie()
   Msginfo("add cat")
 return nil





  static Function ReloadCombo(aItems,cCategoria,cCodcat)
     local nArea  := Select()
     local  cFilter := "(CodCatM1) == '" + cCodcat +  "' .and. !Empty(FIELD->CodCatM2)"
     local  oList:= TCategorie():new()

      asize( aItems, 0 )
      oList:setorder(2)
      oList:setFilter(cfilter)
      oList:Gotop()
     xbrowser  oList
   AaDd(aItems,{"","nessuna"  })
   Do while !oList:eof()
      AAdd( aItems, {oList:CodCatM2,oList:DESCRCATM  })
      oList:Skip()
   EndDo
   oList:close()
   
 Select (nArea)
 return  aItems












//------------------------------------------------------------------------//
CLASS TXData from TDatabase
      DATA cDbfPath   init ".\data\"
ENDCLASS

CLASS TCategorie from TXData
METHOD New()
 METHOD GetList()
ENDCLASS

METHOD New( lShared ) CLASS TCategorie
   Default lShared := .t.
   ::super:New(,::cDbfPath+"
Categorie" ,"DBFCDX", lShared)
   if ::use()
      ::setOrder(1)
      ::gotop()
   endif
   RETURN Self

 METHOD GetList() CLASS TCategorie
   local aTemp:={}
   local  cFilter:= "
Empty(FIELD->CodCatM2)"
   local oList
   local nArea := Select()

   oList:= TCategorie():new()
   oList:SetFilter(cFilter)
   oList:gotop()
         AaDd(atemp,{"
", "Predefinita"  })
        DO While !oList:eof()
             AaDd(atemp,{ oList:CodCatM1,TRIM(oList:DESCRCATM) })
            oList:skip()
         ENDDO
         AaDd(atemp,{ "
","aggiungi"  })
         Select (nArea)
         oList:close()
   return  aTemp









If you want the dbf I can sent you via mail

Both categories and subcategories must have two array elements
in the first there is the category code
in the second there is the description of the category




When show the second combobox the exe crash out

Code: Select all  Expand view  RUN
Application Internal Error - C:\Work\errori\test_categorie\test2.Exe
Terminated at: 2024-04-30 09:22:51
Unrecoverable error 6005: Exception error:

    Exception Code:C0000005 ACCESS_VIOLATION
    Exception Address:778D7685
    EAX:01184D70  EBX:00000000  ECX:00000000  EDX:00000002
    ESI:00000000  EDI:01176E78  EBP:00F5D134
    CS:EIP:0023:778D7685  SS:ESP:002B:00F5D0E8
    DS:002B  ES:002B  FS:0053  GS:002B
    Flags:00010206
    Exception Parameters: 00000000 00000000
    CS:EIP: 66 8B 06 83 C6 02 66 3B C1 75 F5 2B F2 8D 45 D4
    SS:ESP: 00000000 01176E78 00000001 00000001 016C3744 00000000 00000000 00000008 00B9742C 00000000 00000000 00000000 00ACDEA7 00B9742C 00000064 00000000

    C stack:
    EIP:     EBP:       Frame: OldEBP, RetAddr, Params...
    778D7685 00F5D134   00F5D1CC 778D6A32 01176E78 00000000 00000004 01ADE580 00000180 00000000 01602A5C 00000000
    778D6A32 00F5D1CC   00F5D1F8 778D6092 01ADE580 00000000 00000180 00000001 00000000 00000000 0035035C 00000180
    778D6092 00F5D1F8   00F5D224 778A177B 0035035C 00000180 00000001 00000000 0035035C DCBAABCD 77D27FB0 00000180
    778A177B 00F5D224   00F5D30C 77897B6A 77D27FB0 0035035C 00000180 00000001 00000000 500566A8 40000000 C0000388
    77897B6A 00F5D30C   00F5D370 7789776A 77D27FB0 00000000 00000180 00000001 00000000 00D73000 00000001 500566D4
    7789776A 00F5D370   00F5D3B0 778F3A46 01ADE580 00000000 00000180 00000001 00000000 77D27FB0 00000180 778A31A0
    778F3A46 00F5D3B0   00F5D468 77D1507D 00F5D3CC 00000038 00F5D630 77D14FB0 00F5D408 00000068 00000008 00000000
    77D1507D 00F5D468   00F5D500 778C0C13 01ADE580 00000000 00000000 00000001 01ADE430 00000143 00000000 50056130
    778C0C13 00F5D500   00F5D52C 778C076B 01ADE430 00000000 00000143 00000001 00000000 00000001 000F05A2 00000143
    778C076B 00F5D52C   00F5D558 778A177B 000F05A2 00000143 00000001 00000000 000F05A2 DCBAABCD 77D27F80 00000143
    778A177B 00F5D558   00F5D640 77897B6A 77D27F80 000F05A2 00000143 00000001 00000000 500563E4 77D27F80 01ADE430
    77897B6A 00F5D640   00F5D678 77897326 77D27F80 00000000 00000143 00000001 00000000 00000000 00000000 00000001
    77897326 00F5D678   00F5D690 778843BB 00000143 00000001 00000000 00000001
    778843BB 00F5D690   00F5D6B8 007DA446 77D27F80 000F05A2 00000143 00000001 00000000 00000143 000F05A2 000F05A2
    007DA446 00F5D6B8   00F5D6D8 0081A6EF 000F05A2 00000143 00000001 00000000 00000005 0081A6D0
    0081A6EF 00F5D6D8   00F5D704 778A177B 000F05A2 00000143 00000001 00000000 000F05A2 DCBAABCD 0081A6D0 00000143
    778A177B 00F5D704   00F5D7EC 77897B6A 0081A6D0 000F05A2 00000143 00000001 00000000 50056248 00000143 00000000
    77897B6A 00F5D7EC   00F5D850 77898A99 0081A6D0 00000000 00000143 00000001 00000000 00D73000 00000001 00000143
    77898A99 00F5D850   00F5D870 7788453D 01ADE430 00000000 00000000 00000001 00000000 00000000



If I use one dimension for second combobox then run ok But I need two elements
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: 7066
Joined: Thu Oct 18, 2012 7:17 pm

Re: Reload data in a combobox

Postby Silvio.Falconi » Tue Apr 30, 2024 6:23 pm

the second combobox control works fine if I do it in a single dimension, when it tries to repopulate the asubcategory array with two elements it doesn't work and crashes
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: 7066
Joined: Thu Oct 18, 2012 7:17 pm

Re: Reload data in a combobox

Postby nageswaragunupudi » Tue Apr 30, 2024 8:38 pm

I have a sample with similar functionality.
This is working fine.
Please see if you can use this working logic in your application.
Code: Select all  Expand view  RUN
#include "fivewin.ch"

REQUEST DBFCDX

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

function Main()

   local cRegion, cCountry, cCity
   local aRegions, aCountries, aCities
   local oDlg, oFont, oCbx1, oCbx2, oCbx3

   USE CITIES EXCLUSIVE VIA "DBFCDX"

   aRegions    := ReadList( 0 )
   cRegion     := aRegions[ 1, 1 ]
   aCountries  := ReadList( aRegions[ 1, 2 ] )
   cCountry    := aCountries[ 1, 1 ]
   aCities     := ReadList( aCountries[ 1, 2 ] )
   cCity       := aCities[ 1, 1 ]

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-16
   DEFINE DIALOG oDlg SIZE 660, 400 PIXEL TRUEPIXEL FONT oFont

   @ 60, 20 COMBOBOX oCbx1 VAR cRegion ITEMS ArrTranspose( aRegions )[ 1 ] ;
      SIZE 180,300 PIXEL OF oDlg ON CHANGE ( ;
         aCountries := ReadList( aRegions[ oCbx1:nAt, 2 ] ), ;
         oCbx2:SetItems( ArrTranspose( aCountries )[ 1 ] ), ;
         cCountry := aCountries[ 1, 1 ], ;
         oCbx2:Select( 1 ), ;
         oCbx2:Refresh() )

   @ 60,220 COMBOBOX oCbx2 VAR cCountry ITEMS ArrTranspose( aCountries )[ 1 ] ;
      SIZE 180,300 PIXEL OF oDlg ON CHANGE ( ;
         aCities := ReadList( aCountries[ Max( 1, oCbx2:nAt ), 2 ] ), ;
         oCbx3:SetItems( ArrTranspose( aCities )[ 1 ] ), ;
         cCity := aCities[ 1, 1 ], ;
         oCbx3:Refresh() )

   @ 60,420 COMBOBOX oCbx3 VAR cCity ITEMS ArrTranspose( aCities )[ 1 ] ;
      SIZE 180,300 PIXEL OF oDlg

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil

static function ReadList( nParent )
return CITIES->( FW_DbfToArray( "NAME,ID", { || FIELD->PAR = nParent } ) )
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10646
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Reload data in a combobox

Postby Silvio.Falconi » Wed May 01, 2024 7:49 am

nageswaragunupudi wrote:I have a sample with similar functionality.
This is working fine.
Please see if you can use this working logic in your application.
Code: Select all  Expand view  RUN
#include "fivewin.ch"

REQUEST DBFCDX

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

function Main()

   local cRegion, cCountry, cCity
   local aRegions, aCountries, aCities
   local oDlg, oFont, oCbx1, oCbx2, oCbx3

   USE CITIES EXCLUSIVE VIA "DBFCDX"

   aRegions    := ReadList( 0 )
   cRegion     := aRegions[ 1, 1 ]
   aCountries  := ReadList( aRegions[ 1, 2 ] )
   cCountry    := aCountries[ 1, 1 ]
   aCities     := ReadList( aCountries[ 1, 2 ] )
   cCity       := aCities[ 1, 1 ]

   DEFINE FONT oFont NAME "Segoe UI" SIZE 0,-16
   DEFINE DIALOG oDlg SIZE 660, 400 PIXEL TRUEPIXEL FONT oFont

   @ 60, 20 COMBOBOX oCbx1 VAR cRegion ITEMS ArrTranspose( aRegions )[ 1 ] ;
      SIZE 180,300 PIXEL OF oDlg ON CHANGE ( ;
         aCountries := ReadList( aRegions[ oCbx1:nAt, 2 ] ), ;
         oCbx2:SetItems( ArrTranspose( aCountries )[ 1 ] ), ;
         cCountry := aCountries[ 1, 1 ], ;
         oCbx2:Select( 1 ), ;
         oCbx2:Refresh() )

   @ 60,220 COMBOBOX oCbx2 VAR cCountry ITEMS ArrTranspose( aCountries )[ 1 ] ;
      SIZE 180,300 PIXEL OF oDlg ON CHANGE ( ;
         aCities := ReadList( aCountries[ Max( 1, oCbx2:nAt ), 2 ] ), ;
         oCbx3:SetItems( ArrTranspose( aCities )[ 1 ] ), ;
         cCity := aCities[ 1, 1 ], ;
         oCbx3:Refresh() )

   @ 60,420 COMBOBOX oCbx3 VAR cCity ITEMS ArrTranspose( aCities )[ 1 ] ;
      SIZE 180,300 PIXEL OF oDlg

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil

static function ReadList( nParent )
return CITIES->( FW_DbfToArray( "NAME,ID", { || FIELD->PAR = nParent } ) )


on the nigth the last solution was this


Image


the first combobox two element
the second combobox one element

on save I must save the text of categories
I think this problem come from dbf because is the same dbf sample :

cod1 cod2 name
000001 | | one category
000001|000001 | one category of 000001
000001|000002 | second category of 000001

in the school application that we are trying to convert into the new fwh the two category comboboxes (master and sub) were not connected to each other. the source was based on an example of Arteaga's Cawinrc program that Alfredo published in the prehistoric era


Image


and the data are saved in this type :

Image

linea master category
marca sub category
linmar master+sub


on the new app I wish save only the code sample 00001 00002
Tomorrow I will see how to solve this problem
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: 7066
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 66 guests