Page 1 of 1

Edit a xBrowse array

Posted: Fri Mar 05, 2010 11:02 am
by Detlef Hoefner
Hi all,

i try to edit an array value from a xBrowse.
But i can't see the post edit value.
Do i miss something?
Here my code

Code: Select all

REDEFINE XBROWSE oBrw ID 10 OF oDlg;
      ARRAY aArtGrp;
      COLUMNS 1, 2, 4;
      HEADERS "Art.Grp.", "Name", "Target";
      SIZES    50       ,  120  ,  90

   WITH OBJECT oBrw
      :lKineticBrw      := .f.
      :nMarqueeStyle    := MARQSTYLE_HIGHLROW
 
      :oCol( "Target"   ):nEditType  := EDIT_BUTTON 
      :oCol( "Target"   ):addResource( "qty" )
      :oCol( "Target"   ):nBtnBmp    := 1            
      :oCol( "Target"   ):bEditBlock := { || GetNewTarget( oBrw, cKdNr, @nRet ) }
   END
...

STATIC PROCEDURE GetNewTarget( oBrw, cKdNr, xnTarget )
LOCAL oDlg
LOCAL nTarget := 0, oTarget

   DEFINE DIALOG oDlg RESOURCE "GET_TARGET"

   REDEFINE GET oTarget VAR nTarget ID 20 of oDlg PICTURE "@E 9999999" 

   ACTIVATE DIALOG oDlg CENTERED ON PAINT oTarget:SetFocus()

   if oDlg:nResult == ID_OK    
      do while !tgt->( dbAppend() ); enddo
         tgt->kdnr   := cKdNr
         tgt->artgrp := left( cArtGrp, 3 )
         tgt->target := nTarget
      tgt->( DbUnLock() )
      
      xnTarget := nTarget
   endif
   
   oBrw:Refresh()
   oBrw:SetFocus()
RETURN
 
Thanks and regards,
Detlef

Re: Edit a xBrowse array

Posted: Fri Mar 05, 2010 11:48 am
by nageswaragunupudi
bEditBlock should return the new value if edited or old value if not edited.

You may change the bEditBlock as:

Code: Select all

:oCol( "Target"   ):bEditBlock := { || GetNewTarget( oBrw, cKdNr, oBrw:aRow[ 4 ]) }
Please also change STATIC PROCEDURE as STATIC FUNCTION and RETURN xnTarget.

Re: Edit a xBrowse array

Posted: Fri Mar 05, 2010 4:19 pm
by Detlef Hoefner
nageswaragunupudi wrote:bEditBlock should return the new value if edited or old value if not edited.

You may change the bEditBlock as:

Code: Select all

:oCol( "Target"   ):bEditBlock := { || GetNewTarget( oBrw, cKdNr, oBrw:aRow[ 4 ]) }
Please also change STATIC PROCEDURE as STATIC FUNCTION and RETURN xnTarget.
Dear Mr. Rao,

many thanks again for your help.
It's working fine now.

btw,
The part : oBrw:aRow[ 4 ] was not necessary and will make trouble if the user changes the column order.

Regards,
Detlef

Re: Edit a xBrowse array

Posted: Fri Mar 05, 2010 5:01 pm
by nageswaragunupudi
The part : oBrw:aRow[ 4 ] was not necessary and will make trouble if the user changes the column order.
It would not in this case. oBrw:aRow[ 4 ] is same as oBrw:aArrayData[ oBrw:nArrayAt ][ 4 ] and 4 is not column number but your array element.

But I fully agree with you that we should avoid using absolute column numbers in our code. I never use numbers.

I would have written the above code block as :

Code: Select all

oBrw:Target:bEditBlock := { || GetNewTarget( oBrw, cKdNr, oBrw:Target:Value ) }
This code works even if you later change your array structure.