Refresh Xbrowse from value in combobox (SOLVED)

Refresh Xbrowse from value in combobox (SOLVED)

Postby Marc Venken » Thu Sep 07, 2017 11:11 pm

Hey,

I define a Xbrowse like this.

Code: Select all  Expand view  RUN
  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: Select all  Expand view  RUN
  @ 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: Select all  Expand view  RUN

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: Select all  Expand view  RUN
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
 
Last edited by Marc Venken on Sat Sep 09, 2017 12:40 pm, edited 1 time in total.
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1449
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Refresh Xbrowse from value in combobox

Postby nageswaragunupudi » Fri Sep 08, 2017 2:19 am

You can adopt the same logic like this
Code: Select all  Expand view  RUN
  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
User avatar
nageswaragunupudi
 
Posts: 10681
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Refresh Xbrowse from value in combobox

Postby Marc Venken » Sat Sep 09, 2017 9: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: Select all  Expand view  RUN
#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.04 with Harbour
User avatar
Marc Venken
 
Posts: 1449
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium

Re: Refresh Xbrowse from value in combobox

Postby nageswaragunupudi » Sat Sep 09, 2017 11:10 am

If you want the columns read-write then please change the codeblocks this way:

Change
Code: Select all  Expand view  RUN

{ || ( oBrw:cAlias )->( FieldGet( nMonth * 4 + nOffSet ) ) }, ;

as
Code: Select all  Expand view  RUN

{ |x| ( oBrw:cAlias )->( If( x == nil, FieldGet( nMonth * 4 + nOffSet ), FieldPut( nMonth * 4 + nOffSet, x ) ) ) }, ;


Change
Code: Select all  Expand view  RUN

{ { || oRs:FieldGet( tn + 1 ) }       , ;

as
Code: Select all  Expand view  RUN

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

Re: Refresh Xbrowse from value in combobox

Postby Marc Venken » Sat Sep 09, 2017 12:40 pm

Works perfect now !!
Marc Venken
Using: FWH 23.04 with Harbour
User avatar
Marc Venken
 
Posts: 1449
Joined: Tue Jun 14, 2016 7:51 am
Location: Belgium


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 21 guests