FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Refresh Xbrowse from value in combobox (SOLVED)
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Refresh Xbrowse from value in combobox (SOLVED)
Posted: Thu Sep 07, 2017 11:11 PM
Hey,

I define a Xbrowse like this.

Code (fw): Select all Collapse
   aVelden6 :=  { ;
   { "naam"       , "Naam"          ,nil, 125 , NIL}, ; // 3
   { "voornaam"   , "Voornaam"      ,nil, 125 , NIL}, ; // 4
   { "ploeg2017"  , "P2017"          ,"@!", 75, NIL}, ; // 5
   { "truitjesnum", "Num"          ,"999", 50 }, ;   // 16
   { "Actief"     , "Actief"        ,nil,  95 , NIL}, ; // 6
   { "Nonactief"  , "Beschikbaar"    ,"@D",  80 ,NIL},;   // 12
   { "T1_1"       , "T1"             ,"@!",  25 ,2}, ; // 9  // 2 is center
   { "T1_2"       , "T2"             ,"@!",  25 ,2}, ; // 9
   { "T1_3"       , "T3"             ,"@!",  25 ,2}, ; // 9
   { "T1_4"       , "T4"             ,"@!",  25 ,2}, ; // 9
   { "T1_5"       , "T5"             ,"@!",  25 ,2}, ; // 9
   { "T1_6"       , "T6"             ,"@!",  25 ,2}, ; // 9
   { "M1_1"       , "M1"             ,"@!",  45 ,2}, ; // 9
   { "M1_2"       , "M2"             ,"@!",  45 ,2}, ; // 9
   { "M1_3"       , "M3"             ,"@!",  45 ,2}, ; // 9
   { "M1_4"       , "M4"             ,"@!",  45 ,2}, ; // 9
   { "memo"       , "Memo"          ,"@!",  240 ,NIL}}
 

@ 0,0 XBROWSE oBrw[6] size -1,-1 PIXEL OF  oFld:aDialogs[ 6 ] font oFont ;
      DATASOURCE oRs ;
      COLUMNS aVelden6;
      AUTOSORT CELL LINES NOBORDER FOOTERS FASTEDIT


Also a Combobox like this (For selecting a specific month (Januari, Februari,...)

Action : If I change the combo to a new month, the browse should take the new fields.

Code (fw): Select all Collapse
   @ 65,550 COMBOBOX oCbx VAR nMaand SIZE 100,400 PIXEL HEIGHTGET 18 OF oDlg  ;
      ITEMS aMaanden ON CHANGE (changebrowse(nMaand),oBrw[6]:refresh())


and the function (This should update the fields in the Xbrowse array aVelden[6] what is used to create the Xbrowse.
I can't get the Xbrowse refresh with the new fields in the array aVelden [6]

Code (fw): Select all Collapse
Function changebrowse(nMaand)
   for i = 1 to 6
     aVelden6[6+I][1] = "T"+alltrim(str(nMaand))+"_"+alltrim(str(I))
   next

   for i = 1 to 4
     aVelden6[12+I][1] = "M1_"+alltrim(str(i))
   next
 
return


Mr. Rao had a code like this, that is working for DBF. Not for My oRs.

Code (fw): Select all Collapse
function BrowseData()

   local oDlg, oFont, oCbx, oBrw
   local nMonth   := 1
   local aMonths[ 12 ]
   local nOffSet

   AEval( aMonths, { |c,i| aMonths[ i ] := NtoCMonth( i ) } )
   nOffSet     := MARCV->( FIELDPOS( "T1_1" ) ) - 4

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-15
   DEFINE DIALOG oDlg SIZE 400,400 PIXEL TRUEPIXEL FONT oFont

   @ 20,20 COMBOBOX oCbx VAR nMonth SIZE 200,400 PIXEL OF oDlg ;
      ITEMS aMonths ON CHANGE oBrw:Refresh()

   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE "MARCV" ;
      COLUMNS "ID", "Name", ;
         { || ( oBrw:cAlias )->( FieldGet( nMonth * 4 + nOffSet ) ) }, ;
         { || ( oBrw:cAlias )->( FieldGet( nMonth * 4 + nOffSet + 1 ) ) }, ;
         { || ( oBrw:cAlias )->( FieldGet( nMonth * 4 + nOffSet + 2 ) ) }, ;
         { || ( oBrw:cAlias )->( FieldGet( nMonth * 4 + nOffSet + 3 ) ) }  ;
      HEADERS nil, nil, "C1", "C2", "C3", "C4" ;
      PICTURES nil, nil, "9999", "9999", "9999", "9999" ;
      CELL LINES NOBORDER

   WITH OBJECT oBrw
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Refresh Xbrowse from value in combobox
Posted: Fri Sep 08, 2017 02:19 AM
You can adopt the same logic like this
Code (fw): Select all Collapse
   tn    := oRs:FieldPos( "T1_1" )
   aVelden6 :=  { ;
    { "naam"       , "Naam"          ,nil, 125 , NIL}, ; // 3
    { "voornaam"   , "Voornaam"      ,nil, 125 , NIL}, ; // 4
    { "ploeg2017"  , "P2017"          ,"@!", 75, NIL}, ; // 5
    { "truitjesnum", "Num"          ,"999", 50 }, ;   // 16
    { "Actief"     , "Actief"        ,nil,  95 , NIL}, ; // 6
    { "Nonactief"  , "Beschikbaar"    ,"@D",  80 ,NIL},;   // 12
    { { || oRs:FieldGet( tn ) }       , ;
                     "T1"             ,"@!",  25 ,2}, ; // 9  // 2 is center
    { { || oRs:FieldGet( tn + 1 ) }       , ;
                     "T2"             ,"@!",  25 ,2}, ; // 9
    { { || oRs:FieldGet( tn + 2 ) }       , ;
                     "T3"             ,"@!",  25 ,2}, ; // 9
    { { || oRs:FieldGet( tn + 3 ) }       , ;
                     "T4"             ,"@!",  25 ,2}, ; // 9
    { { || oRs:FieldGet( tn + 4 ) }       , ;
                     "T5"             ,"@!",  25 ,2}, ; // 9
    { { || oRs:FieldGet( tn + 5 ) }       , ;
                     "T6"             ,"@!",  25 ,2}, ; // 9
    { "M1_1"       , "M1"             ,"@!",  45 ,2}, ; // 9
    { "M1_2"       , "M2"             ,"@!",  45 ,2}, ; // 9
    { "M1_3"       , "M3"             ,"@!",  45 ,2}, ; // 9
    { "M1_4"       , "M4"             ,"@!",  45 ,2}, ; // 9
    { "memo"       , "Memo"          ,"@!",  240 ,NIL}}
 

@ 0,0 XBROWSE oBrw[6] size -1,-1 PIXEL OF  oFld:aDialogs[ 6 ] font oFont ;
      DATASOURCE oRs ;
      COLUMNS aVelden6;
      AUTOSORT CELL LINES NOBORDER FOOTERS FASTEDIT



 @ 65,550 COMBOBOX oCbx VAR nMaand SIZE 100,400 PIXEL HEIGHTGET 18 OF oDlg  ;
      ITEMS aMaanden ON CHANGE ( ;
         tn := oRs:FieldPos( "T" + LTrim( Str( nMaand ) ) + "_1" ), ;
         oBrw[ 6 ]:Refresh() )
Regards



G. N. Rao.

Hyderabad, India
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Refresh Xbrowse from value in combobox
Posted: Sat Sep 09, 2017 09:50 AM
Mr. Rao,

With this code, the Xbrowse will not allow to edit the fields? You can type them, but the values don't change.

In your original sample, the values also don't change.

See your code. I only added oBrw:nEditTypes = EDIT_GET

Code (fw): Select all Collapse
#include "fivewin.ch"

REQUEST DBFCDX

function Main()

   OpenData()
   BrowseData()

return nil

function BrowseData()

   local oDlg, oFont, oCbx, oBrw
   local nMonth   := 1
   local aMonths[ 12 ]
   local nOffSet

   AEval( aMonths, { |c,i| aMonths[ i ] := NtoCMonth( i ) } )
   nOffSet     := MARCV->( FIELDPOS( "T1_1" ) ) - 4

   DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-15
   DEFINE DIALOG oDlg SIZE 400,400 PIXEL TRUEPIXEL FONT oFont

   @ 20,20 COMBOBOX oCbx VAR nMonth SIZE 200,400 PIXEL OF oDlg ;
      ITEMS aMonths ON CHANGE oBrw:Refresh()

   @ 60,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
      DATASOURCE "MARCV" ;
      COLUMNS "ID", "Name", ;
         { || ( oBrw:cAlias )->( FieldGet( nMonth * 4 + nOffSet ) ) }, ;
         { || ( oBrw:cAlias )->( FieldGet( nMonth * 4 + nOffSet + 1 ) ) }, ;
         { || ( oBrw:cAlias )->( FieldGet( nMonth * 4 + nOffSet + 2 ) ) }, ;
         { || ( oBrw:cAlias )->( FieldGet( nMonth * 4 + nOffSet + 3 ) ) }  ;
      HEADERS nil, nil, "C1", "C2", "C3", "C4" ;
      PICTURES nil, nil, "9999", "9999", "9999", "9999" ;
      CELL LINES NOBORDER FASTEDIT

   oBrw:nEditTypes = EDIT_GET

   WITH OBJECT oBrw
      :CreateFromCode()
   END

   ACTIVATE DIALOG oDlg CENTERED
   RELEASE FONT oFont

return nil

function OpenData()

   CreateData()

   USE MARCV NEW SHARED VIA "DBFCDX"

return nil

function CreateData()

   local aCols    := { { "ID",  "+", 4, 0 }, { "NAME", "C", 6, 0 } }
   local i, j, c, a

   for i := 1 to 12
      for j := 1 to 4
         c  := "T" + LTrim( Str( i ) ) + "_" + Str( j, 1 )
         AAdd( aCols, { c, "N", 4, 0 } )
      next
   next

   DBCREATE( "MARCV", aCols, "DBFCDX", .T., "DB" )

   for i := 1 to 10
      APPEND BLANK
      FIELD->NAME    := "Name" + StrZero( i, 2 )
      for j := 3 to FCOUNT()
         FieldPut( j, HB_RandomInt( 10,9999 ) )
      next
   next
   CLOSE DATA

return nil
Marc Venken

Using: FWH 23.08 with Harbour
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Refresh Xbrowse from value in combobox
Posted: Sat Sep 09, 2017 11:10 AM
If you want the columns read-write then please change the codeblocks this way:

Change
Code (fw): Select all Collapse
{ || ( oBrw:cAlias )->( FieldGet( nMonth * 4 + nOffSet ) ) }, ;

as
Code (fw): Select all Collapse
{ |x| ( oBrw:cAlias )->( If( x == nil, FieldGet( nMonth * 4 + nOffSet ), FieldPut( nMonth * 4 + nOffSet, x ) ) ) }, ;


Change
Code (fw): Select all Collapse
{ { || oRs:FieldGet( tn + 1 ) }       , ;

as
Code (fw): Select all Collapse
{ { |x| If( x == nil, oRs:FieldGet( tn + 1 ), oRs:FieldPut( tn + 1, x ) ) }       , ;


I gave sample for one column. Please change all other similar codeblocks also.
Regards



G. N. Rao.

Hyderabad, India
Posts: 1487
Joined: Tue Jun 14, 2016 07:51 AM
Re: Refresh Xbrowse from value in combobox
Posted: Sat Sep 09, 2017 12:40 PM

Works perfect now !!

Marc Venken

Using: FWH 23.08 with Harbour

Continue the discussion