FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Sincronizar combobox con evento Xbrowse (SOLUCIONADO)
Posts: 607
Joined: Mon Mar 04, 2013 04:32 PM
Sincronizar combobox con evento Xbrowse (SOLUCIONADO)
Posted: Sat Apr 10, 2021 06:03 PM
Hola:

Como intento explicar en el asunto. El tema es este, a ver si logro explicarlo.
Tengo una barra de botones con un combobox que cambia el indice de ordenacion de un XBrowse. Perfecto.
para hacer esto en el evento ON CHANGE del combobox utilizo una funcion trivial

Code (fw): Select all Collapse
FUNCTION IndexAlias(cAlias, oBrw )

   LOCAL cIndice := (cAlias)->( ordSetFocus() )

   IF cIndice == "CODIGO"
      (cAlias)->( ordSetFocus( 2 ) )
   ELSE
      (cAlias)->( ordSetFocus( 1 ) )
   ENDIF

   (cAlias)->( dbGoTop() )

   oBrw:Refresh() // Repintamos el ListBox
   oBrw:SetFocus()

RETURN NIL


Tengo un Xbrowse que pulsando en la columna ordeno por codigo, nombre (Lo habitual vamos)

Como hago para sincronizar los dos controles ?

Cuando hago click en la columna del Xbrowse se deberia de refrescar el combobox cambiando el indice de ordenacion realmente activo. (Ya que ha cambiado)
y viceversa cuando cambio en el combobox el indice de ordenacion se deberia de activar la columna elegida.

Espero vuestros consejos.

Saludos.

Jose.
Fwh 24.07 64 bits + Harbour 64 bits 3.2dev(r2407221137) + MSVC64
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Sincronizar combobox con evento Xbrowse
Posted: Sun Apr 11, 2021 07:08 AM
Code (fw): Select all Collapse
#include "fivewin.ch"

function Main()

   local oDlg, oBrw, oCbx, cOrder
   local aOrders, aCols

   FERASE( "CUSTOMER.CDX" )
   USE CUSTOMER NEW VIA "DBFCDX" EXCLUSIVE
   FW_CdxCreate()
   SET ORDER TO TAG FIRST
   GO TOP
   cOrder   := "FIRST"
   aOrders  := { cOrder }

   DEFINE DIALOG oDlg SIZE 600,400 PIXEL TRUEPIXEL

   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE "CUSTOMER" ;
      COLUMNS "FIRST", "CITY", "STATE", "SALARY" ;
      CELL LINES NOBORDER AUTOSORT

   WITH OBJECT oBrw

#if FW_VersionNo >= 20070
      :bOnSort   := { |b,c| cOrder := c:cSortOrder, oCbx:Refresh() }
#else
      :bOnRefresh := < ||
         local nAt
         if ( nAt := AScan( oBrw:aCols, { |o| !Empty( o:cOrder ) } ) ) > 0
            cOrder   := oBrw:aCols[ nAt ]:cSortOrder
            oCbx:Refresh()
         endif
         return nil
         >
#endif
      :CreateFromCode()
   END

   @ 15,20 COMBOBOX oCbx VAR cOrder SIZE 100,400 PIXEL OF oDlg ITEMS aOrders ;
      ON CHANGE ( aCols[ oCbx:nAt ]:SetOrder(), oBrw:Refresh() )

   oDlg:bInit := <||
      aOrders     := {}
      aCols       := {}
      AEval( oBrw:aCols, { |o| AAdd( aOrders, o:cSortOrder ), AAdd( aCols, o ) } )
      oCbx:SetItems( aOrders, .f. )
      oCbx:Set( aOrders[ 1 ] )
      oCbx:Refresh()
      return nil
      >


   ACTIVATE DIALOG oDlg CENTERED

return nil
Regards



G. N. Rao.

Hyderabad, India
Posts: 607
Joined: Mon Mar 04, 2013 04:32 PM
Re: Sincronizar combobox con evento Xbrowse
Posted: Sun Apr 11, 2021 10:57 AM
Hi Mr. Rao.

Many thanks for your help, your code works perfectly.

but I use for show the combobox an Control BUTTONBAR and window is MDICHILD, too when i activate the window MDICHILD
i have this code.

Code (fw): Select all Collapse
 @ .31, 56.6 COMBOBOX oCombo VAR cOrder ITEMS aCombo ON CHANGE ( aCols[ oCombo:nAt ]:SetOrder(), oBrw:Refresh() ) ;
   SIZE 125, 36 FONT oArial ;
   MESSAGE "Cambia el indice de ordenación" WHEN Obr->( LastRec() ) > 0 OF oBar   // Combo is in BAR Object
   oCombo:cTooltip := "Cambia el indice de ordenación"

oBar:bInit := <||  
      aCombo     := {}
      aCols      := {}
      AEval( oBrw:aCols, { |o| AAdd( aCombo, o:cSortOrder ), AAdd( aCols, o ) } )
      oCombo:SetItems( aCombo, .f. )
      oCombo:Set( aCombo[ 1 ] )
      oCombo:Refresh()
      return nil
      >    
   // oWndObr is an MIDCHILD
   ACTIVATE WINDOW OWndObr VALID ( oMenuObr:Enable(), oObra:Enable(),SaveWinData(oWndObr,oBrw,cAlias),CierraIndex(oWndObr,cAlias) ) ;
   ON INIT ReadWinData(oWndObr,oBrw,cAlias)


The program compiles and runs without errors but seems it not loads the fields in the Combobox .
how solve this ?

Thanks Mr. Rao.

Jose.
Fwh 24.07 64 bits + Harbour 64 bits 3.2dev(r2407221137) + MSVC64
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Sincronizar combobox con evento Xbrowse
Posted: Sun Apr 11, 2021 11:00 AM

INIT is required for Dialogs only.
In the case of browses on window, you can write the same code immediately after oBrw:CreateFromCode()

Regards



G. N. Rao.

Hyderabad, India
Posts: 607
Joined: Mon Mar 04, 2013 04:32 PM
Re: Sincronizar combobox con evento Xbrowse
Posted: Sun Apr 11, 2021 02:30 PM
Thanks Mr. Rao.

With WINDOWS CLASS works fine too.

only a problem with indocumented funcion

Code (fw): Select all Collapse
FW_CdxCreate()


This funcition creates an index for each field and I use in my program
cdx index, but not have indexed all fields.

and without this function your code not works.

you can adapt your code for use with my cdx index

Waiting your responde.

Regards

Jose.
Fwh 24.07 64 bits + Harbour 64 bits 3.2dev(r2407221137) + MSVC64
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Sincronizar combobox con evento Xbrowse
Posted: Mon Apr 12, 2021 02:54 AM
Please try this:
Code (fw): Select all Collapse
#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   local oWnd, oBar

   DEFINE WINDOW oWnd MDI
   DEFINE BUTTONBAR oBar OF oWnd SIZE 100,32 2007
   DEFINE BUTTON OF oBar PROMPT "TEST" ACTION ChildBrw()

   ACTIVATE WINDOW oWnd CENTERED

return nil

function ChildBrw()

   local oWnd, oBar, oBrw, oCbx, cAlias, cOrder
   local aOrders, aCols

   USE CUSTOMER NEW SHARED ALIAS ( cGetNewAlias( "CUST" ) ) VIA "DBFCDX"
   cAlias   := ALIAS()
   SET ORDER TO TAG FIRST
   GO TOP

   DEFINE WINDOW oWnd MDICHILD OF WndMain()
   DEFINE BUTTONBAR oBar OF oWnd SIZE 64,32 2007
   DEFINE BUTTON OF oBar PROMPT "New"    CENTER ACTION oBrw:EditSource( .t. )
   DEFINE BUTTON OF oBar PROMPT "Edit"   CENTER ACTION oBrw:EditSource()
   DEFINE BUTTON OF oBar PROMPT "Delete" CENTER ACTION If( MsgNoYes( "Delete?" ), oBrw:Delete(), )

   @ 0,0 XBROWSE oBrw SIZE 0,0 PIXEL OF oWnd ;
      DATASOURCE cAlias AUTOCOLS AUTOSORT ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw

#if FW_VersionNo >= 20070
      :bOnSort   := { |b,c| cOrder := c:cSortOrder, oCbx:Refresh() }
#else
      :bOnRefresh := < ||
         local nAt
         if ( nAt := AScan( oBrw:aCols, { |o| !Empty( o:cOrder ) } ) ) > 0
            cOrder   := oBrw:aCols[ nAt ]:cSortOrder
            oCbx:Refresh()
         endif
         return nil
         >
#endif
      :CreateFromCode()
   END

   aOrders     := {}
   aCols       := {}
   AEval( oBrw:aCols, { |o| If( Empty( o:cSortOrder ),,( AAdd( aOrders, o:cSortOrder ), AAdd( aCols, o ) ) ) } )
   cOrder      := ( cAlias )->( OrdSetFocus() )

   @ 01,250 COMBOBOX oCbx VAR cOrder SIZE 200,400 PIXEL OF oBar ITEMS aOrders ;
      ON CHANGE ( aCols[ oCbx:nAt ]:SetOrder(), oBrw:Refresh() )

   oWnd:oClient   := oBrw
   oWnd:bPostEnd  := { || ( cAlias )->( DBCLOSEAREA() ) }

   ACTIVATE WINDOW oWnd

return nil
Regards



G. N. Rao.

Hyderabad, India
Posts: 607
Joined: Mon Mar 04, 2013 04:32 PM
Re: Sincronizar combobox con evento Xbrowse
Posted: Mon Apr 12, 2021 05:08 PM

Many Thanks Mr. Rao.

Awesome, It works perfectly, sample very clear.

I think is candidate for include in fwh\samples\sincCbxBrw.prg :P

Congrats.

Jose.

Fwh 24.07 64 bits + Harbour 64 bits 3.2dev(r2407221137) + MSVC64
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Sincronizar combobox con evento Xbrowse (SOLUCIONADO)
Posted: Tue Apr 13, 2021 12:33 PM
FWH 2103 simplifies it all:
This is what all required:
Code (fw): Select all Collapse
   USE CUSTOMER NEW VIA "DBFCDX"
   SET ORDER TO TAG FIRST
   GO TOP

   DEFINE DIALOG oDlg SIZE 800,600 PIXEL TRUEPIXEL RESIZABLE

   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE ALIAS() AUTOCOLS AUTOSORT ;
      CELL LINES NOBORDER

   oBrw:CreateFromCode()

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

   ACTIVATE DIALOG oDlg CENTERED


The programmer does not have to write any more code than this single line:
Code (fw): Select all Collapse
   @ 10,20 COMBOBOX oBrw:oSortCbx VAR oBrw:cSortOrder SIZE 100,400 PIXEL OF oDlg
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Sincronizar combobox con evento Xbrowse (SOLUCIONADO)
Posted: Wed Apr 14, 2021 06:06 AM
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion