Edit a xBrowse array

Post Reply
User avatar
Detlef Hoefner
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany
Contact:

Edit a xBrowse array

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

Re: Edit a xBrowse array

Post 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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
Detlef Hoefner
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany
Contact:

Re: Edit a xBrowse array

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

Re: Edit a xBrowse array

Post 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.
Regards

G. N. Rao.
Hyderabad, India
Post Reply