Edit a xBrowse array

Edit a xBrowse array

Postby Detlef Hoefner » Fri Mar 05, 2010 11:02 am

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  Expand view
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
Detlef Hoefner
 
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany

Re: Edit a xBrowse array

Postby nageswaragunupudi » Fri Mar 05, 2010 11:48 am

bEditBlock should return the new value if edited or old value if not edited.

You may change the bEditBlock as:
Code: Select all  Expand view
: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
nageswaragunupudi
 
Posts: 10627
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Edit a xBrowse array

Postby Detlef Hoefner » Fri Mar 05, 2010 4:19 pm

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  Expand view
: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
Detlef Hoefner
 
Posts: 312
Joined: Sat Oct 08, 2005 9:12 am
Location: Germany

Re: Edit a xBrowse array

Postby nageswaragunupudi » Fri Mar 05, 2010 5:01 pm

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 100 guests