XBROWSE - How to change the oRowSet (SOLVED)

XBROWSE - How to change the oRowSet (SOLVED)

Postby vilian » Mon Feb 11, 2019 10:53 am

Hi Huys,

I need to change completely the content of a xBrowse at run time. The oRowSet, the ttitles and the formats of the columns. Is it possible ?
Last edited by vilian on Tue Feb 12, 2019 11:48 am, edited 1 time in total.
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 982
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: XBROWSE - How to change the oRowSet

Postby Marc Venken » Mon Feb 11, 2019 11:32 am

For the headers :

Code: Select all  Expand view  RUN

   Public aVelden1:=  { ;
   { "klant_nr"           , "Code" , NIL,  65 }, ; // 1
   { "naam_1"             , "Naam" , NIL, 240 }, ; //
   { "gemeente"           , "Gemeente" , NIL, 110 }, ; // 1
   { "dat_lst"            , "DatLST" , NIL, 70 }, ; // 1
   { "Jaar_1"             , "J1" , NIL, 75 }, ; // 1
   { "Jaar_2"             , "J1" , NIL, 75 }, ; // 1
   { "Jaar_3"             , "J1" , NIL, 75 }, ; // 1
   { "Jaar_4"             , "J1" , NIL, 75 }, ; // 1
   { "Jaar_5"             , "J1" , NIL, 75 }, ; // 1
   { "totomzet"             , "omzet" , NIL, 70 }}   // 1

   @ 55,0 XBROWSE oBrw[1] size -1,-1 PIXEL OF  oFld:aDialogs[ 1 ] font oFonts ;
      DATASOURCE "klant" ;
      COLUMNS aVelden1;
      AUTOSORT CELL LINES NOBORDER FOOTERS

     oBrw[1]:cHeaders := { 'Code','Naam','Gemeente','Dat_LST',str(year(date()),4),str(year(date())-1,4),str(year(date())-2,4),str(year(date())-3,4),str(year(date())-4,4),'Totaal' }
     oBrw[1]:SetChecks()
     oBrw[1]:bRClicked := { || XbrShowSizes( oBrw[1] )  }
     //oBrw[1]:nStretchCol  := STRETCHCOL_WIDEST
     oBrw[1]:CreateFromCode()

 
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1456
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: XBROWSE - How to change the oRowSet

Postby Marc Venken » Mon Feb 11, 2019 11:36 am

To call them by name if nessesary

Code: Select all  Expand view  RUN

WITH OBJECT :oCol( "J_" + Str( Year( Date() ), 4 ) )
 


If you put "J_" in front.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1456
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: XBROWSE - How to change the oRowSet

Postby vilian » Mon Feb 11, 2019 12:29 pm

Thank you Mark,

But I also must to change the datasource/oRowSet. In your sample, I just saw the changes of headers.
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 982
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: XBROWSE - How to change the oRowSet

Postby horacio » Mon Feb 11, 2019 6:03 pm

Prueba

Code: Select all  Expand view  RUN

oBrw : SetODbf( oRowSet )
 


Saludos
horacio
 
Posts: 1363
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: XBROWSE - How to change the oRowSet

Postby nageswaragunupudi » Tue Feb 12, 2019 2:24 am

Switching Rowsets dynamically at runtime:

Use:
Code: Select all  Expand view  RUN

oRsNew:ResetXBr( oBrw ) // oBrw is the running xbrowse
oRsNew:SetXbrColumns( oBrw, [aCols] ) // If aCols is ommitted, all columns
oBrw:Refresh()
 


Try this sample.
Code: Select all  Expand view  RUN
#include "fivewin.ch"

function Main()

   local oCn, oStates, oCust
   local aStateCols, aCustCols
   local oDlg, oBrw

   oCn      := FW_DemoDB()
   oStates  := oCn:RowSet( "states" )
   oCust    := oCn:RowSet( "customer" )

   aStateCols  := { "Code", "Name" }
   aCustCols   := { { "First", "CustName" }, ;
                    { "Age", "CustAge" }, ;
                    { "Salary", "Due", "99,999,999.99" } }

   DEFINE DIALOG oDlg SIZE 400,500 PIXEL TRUEPIXEL

   @ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oStates COLUMNS aStateCols ;
      CELL LINES NOBORDER FASTEDIT FOOTERS

   oBrw:CreateFromCode()

   @ 10, 20 BTNBMP PROMPT "Customer" SIZE 100,40 PIXEL OF oDlg FLAT ACTION ;
      (  oCust:ResetXbr( oBrw ), oCust:SetXbrColumns( oBrw, aCustCols ), ;
         oBrw:lFooter := .t., ;
         oBrw:Due:nFooterType := AGGR_SUM, ;
         oBrw:MakeTotals(), ;
         oBrw:Refresh() )

   @ 10,120 BTNBMP PROMPT "States" SIZE 100,40 PIXEL OF oDlg FLAT ACTION ;
      (  oStates:ResetXbr( oBrw ), oStates:SetXbrColumns( oBrw, aStateCols ), ;
         oBrw:lFooter := .f., ;
         oBrw:Refresh() )

   @ 10,220 BTNBMP PROMPT "EDIT" SIZE 100,40 PIXEL OF oDlg FLAT ACTION oBrw:EditSource()

   ACTIVATE DIALOG oDlg CENTERED

   oStates:Close()
   oCust:Close()
   oCn:Close()

return nil
 

You need recent version of FWH.
Regards

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

Re: XBROWSE - How to change the oRowSet

Postby nageswaragunupudi » Tue Feb 12, 2019 3:02 am

In the previous post we demonstrated how to switch different rowsets (including different configuration of columns) dynamically at runtime.

It is also possible to switch the same rowset to a totally different query (different table too). It is possible even to switch to a different connection too.

Code: Select all  Expand view  RUN

oRs:oCn := oNewCon  // optional
oRs:ReQuery( "select * from different_table" )
oRs:SetXbrColumns( oBrw, [aCols] )
oBrw:Refresh()
 


This is a working sample:
Code: Select all  Expand view  RUN
#include "fivewin.ch"

function Main()

   local oCn, oRs
   local aStateCols, aCustCols
   local oDlg, oBrw

   oCn      := FW_DemoDB()
   oRs      := oCn:RowSet( "states" )

   aStateCols  := { "Code", "Name" }
   aCustCols   := { { "First", "CustName" }, ;
                    { "Age", "CustAge" }, ;
                    { "Salary", "Due", "99,999,999.99" } }

   DEFINE DIALOG oDlg SIZE 400,500 PIXEL TRUEPIXEL

   @ 70,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE oRs COLUMNS aStateCols ;
      CELL LINES NOBORDER FASTEDIT FOOTERS

   oBrw:CreateFromCode()

   @ 10, 20 BTNBMP PROMPT "Customer" SIZE 100,40 PIXEL OF oDlg FLAT ACTION ;
      (  oRs:Requery( "select * from customer" ), ;
         oRs:SetXbrColumns( oBrw, aCustCols ), ;
         oBrw:lFooter := .t., ;
         oBrw:Due:nFooterType := AGGR_SUM, ;
         oBrw:MakeTotals(), ;
         oBrw:Refresh() )

   @ 10,120 BTNBMP PROMPT "States" SIZE 100,40 PIXEL OF oDlg FLAT ACTION ;
      (  oRs:Requery( "select * from states" ), ;
         oRs:SetXbrColumns( oBrw, aStateCols ), ;
         oBrw:lFooter := .f., ;
         oBrw:Refresh() )

   @ 10,220 BTNBMP PROMPT "EDIT" SIZE 100,40 PIXEL OF oDlg FLAT ACTION oBrw:EditSource()

   ACTIVATE DIALOG oDlg CENTERED

   oRs:Close()
   oCn:Close()

return nil
 


You need recent version of FWH.
Regards

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

Re: XBROWSE - How to change the oRowSet

Postby vilian » Tue Feb 12, 2019 11:06 am

Thank you Mr Rao,

It's exactly I was needing. Is this working from which version of FWH(I'm using 18 07) ?
Sds,
Vilian F. Arraes
vilian@vfatec.com.br
Belém-Pa-Brazil
User avatar
vilian
 
Posts: 982
Joined: Wed Nov 09, 2005 2:17 am
Location: Brazil

Re: XBROWSE - How to change the oRowSet

Postby nageswaragunupudi » Tue Feb 12, 2019 11:09 am

Please try with your version and let me know if it is working for you.
Regards

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

Re: XBROWSE - How to change the oRowSet

Postby nageswaragunupudi » Tue Feb 12, 2019 11:10 am

Also please see this:
viewtopic.php?f=3&t=36740
Regards

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 89 guests