Sincronizar combobox con evento Xbrowse (SOLUCIONADO)

Sincronizar combobox con evento Xbrowse (SOLUCIONADO)

Postby jvtecheto » Sat Apr 10, 2021 6: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: Select all  Expand view

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.
Last edited by jvtecheto on Mon Apr 12, 2021 5:11 pm, edited 1 time in total.
Fwh 24.07 64 bits + Harbour 64 bits 3.2dev(r2407221137) + MSVC64
User avatar
jvtecheto
 
Posts: 593
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain

Re: Sincronizar combobox con evento Xbrowse

Postby nageswaragunupudi » Sun Apr 11, 2021 7:08 am

Code: Select all  Expand view
#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
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Sincronizar combobox con evento Xbrowse

Postby jvtecheto » 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: Select all  Expand view

 @ .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
User avatar
jvtecheto
 
Posts: 593
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain

Re: Sincronizar combobox con evento Xbrowse

Postby nageswaragunupudi » 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
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Sincronizar combobox con evento Xbrowse

Postby jvtecheto » Sun Apr 11, 2021 2:30 pm

Thanks Mr. Rao.

With WINDOWS CLASS works fine too.

only a problem with indocumented funcion

Code: Select all  Expand view

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
User avatar
jvtecheto
 
Posts: 593
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain

Re: Sincronizar combobox con evento Xbrowse

Postby nageswaragunupudi » Mon Apr 12, 2021 2:54 am

Please try this:
Code: Select all  Expand view
#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
User avatar
nageswaragunupudi
 
Posts: 10624
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Sincronizar combobox con evento Xbrowse

Postby jvtecheto » Mon Apr 12, 2021 5: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
User avatar
jvtecheto
 
Posts: 593
Joined: Mon Mar 04, 2013 4:32 pm
Location: Spain

Re: Sincronizar combobox con evento Xbrowse (SOLUCIONADO)

Postby nageswaragunupudi » Tue Apr 13, 2021 12:33 pm

FWH 2103 simplifies it all:
This is what all required:
Code: Select all  Expand view
  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: Select all  Expand view

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

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

Re: Sincronizar combobox con evento Xbrowse (SOLUCIONADO)

Postby nageswaragunupudi » Wed Apr 14, 2021 6:06 am

Regards

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


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 58 guests