Page 1 of 1

array browser delete issue

Posted: Fri Mar 11, 2022 5:01 pm
by Detlef
Dear All,
I have an xBrowse using an array.
Strange thing happens, when deleting a row.

If the last row is selected and I press the delete button, it's working fine.
If any other row is selected deleting doesn't work correctly.
Only the first column element of the row is deleted and the following column values shift to the left.
Please, can someone give me an advice to get this working?

Code: Select all | Expand

#include "FiveWin.ch"
#include "xbrowse.ch"

FUNCTION Main()
//-------------
LOCAL oBrw, oDlg
LOCAL aData := CreateArray()


   DEFINE DIALOG oDlg FROM 2,2 TO 24, 46 OF oDlg TITLE "Test Delete An Array Row"

   @ 1.5, 1 XBROWSE oBrw OF oDlg             ;
      HEADERS "Name", "Interest", "Age "     ;
      SIZE 160, 135                          ;
      COLSIZES 100,  100,  80                ;
      JUSTIFY  AL_LEFT, AL_CENTER, AL_CENTER ;
      ARRAY aData AUTOCOLS

   oBrw:CreateFromCode()

   @ 0.2,  1 BUTTON "&add" OF oDlg  SIZE 30,12;
     ACTION addRow( oBrw, aData )

   @ 0.2,  8 BUTTON "&delete" OF oDlg  SIZE 30,12 ;
     ACTION delRow( oBrw, aData )

   @ 0.2, 15 BUTTON "e&xit" OF oDlg  SIZE 30,12 ;
     ACTION oDlg:End()

   ACTIVATE DIALOG oDlg ON INIT( oDlg:center() )

RETURN NIL

PROCEDURE addRow( oBrw, a )
//-------------------------
   aadd( a, aMakePerson() )
   oBrw:Refresh()
   oBrw:GoBottom()
RETURN

PROCEDURE delRow( oBrw, a )
//-------------------------
   MsgInfo( "deleting row # " + alltrim( str( oBrw:nArrayAt ) ) )
   adel( a[ oBrw:nArrayAt], .t. )
   aSize( a, len( a ) - 1 )
   oBrw:Refresh()
RETURN

FUNCTION CreateArray()
//--------------------
LOCAL aRet := {}
LOCAL n

   for n := 1 to 5
      aadd( aRet, aMakePerson() )
   next
RETURN( aRet )

FUNCTION aMakePerson()
//--------------------
LOCAL aInterest := { "Golf", "Football", "Knitting", "Singing", "Drinking" }
LOCAL aPeople   := { "Jack", "Melissa", "Ernest", "George", "Melvin", "Brovira", "June", "Mike", "Penelope", "Stan", "Laurel" }

RETURN( { aPeople[ hb_RandomInt( 1, Len( aPeople ) ) ],;
             aInterest[ hb_RandomInt( 1, Len( aInterest ) ) ],;
             hb_RandomInt( 18, 100 ) } )
 

Re: array browser delete issue

Posted: Fri Mar 11, 2022 5:57 pm
by artu01
try

Code: Select all | Expand


PROCEDURE delRow( oBrw, a )
//-------------------------
   MsgInfo( "deleting row # " + alltrim( str( oBrw:nArrayAt ) ) )
   oBrw:delete()
   //oBrw:Refresh()
RETURN
 

Re: array browser delete issue

Posted: Fri Mar 11, 2022 7:56 pm
by Detlef
Thanks, artu01.
I tried but then nothing is deleted.
No effect on screen and the lenght of my array remains unchanged.

Re: array browser delete issue

Posted: Fri Mar 11, 2022 8:06 pm
by FranciscoA
Detlef wrote:Dear All,
I have an xBrowse using an array.
Strange thing happens, when deleting a row.

If the last row is selected and I press the delete button, it's working fine.
If any other row is selected deleting doesn't work correctly.
Only the first column element of the row is deleted and the following column values shift to the left.
Please, can someone give me an advice to get this working?

Code: Select all | Expand

#include "FiveWin.ch"

PROCEDURE delRow( oBrw, a )
//-------------------------
   MsgInfo( "deleting row # " + alltrim( str( oBrw:nArrayAt ) ) )
   adel( a[ oBrw:nArrayAt], .t. )
   aSize( a, len( a ) - 1 )
   oBrw:Refresh()
RETURN

 


Intenta asi:
Try this way:

Code: Select all | Expand

PROCEDURE delRow( oBrw, a )
//-------------------------
   MsgInfo( "deleting row # " + alltrim( str( oBrw:nArrayAt ) ) )
   adel( a, oBrw:nArrayAt, .t. )
oBrw:Refresh()
RETURN
 

Re: array browser delete issue

Posted: Fri Mar 11, 2022 8:59 pm
by Detlef
Many thanks, Francisco.
I'm glad for your advice.
Now it's working okay.