Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Delete records in grid and compute total
Message
From
05/10/2004 07:10:40
 
 
To
04/10/2004 14:53:47
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00947104
Message ID:
00948748
Views:
44
i'm sorry if i make you angry.

I am not angry.

Let's take this from the beginning.

Add a custom method to your form called DeleteRecord.

This code goes in the DeleteRecord() method:
LPARAMETERS tnRecNo
LOCAL lcAlias, loColumn
lcAlias = Thisform.Grid1.recordSOurce
*** The current record may not be the one we are trying to delete, that is,
*** the paramter to the deleted() method (nRecoNo) may not be the same as RECNO()
*** and if we just added it, RECNO( .RecordSource ) WILL be a negative number but nRecNo 
*** will be a positive one! So if you are using table buffering and not TABLEUPDATEing
*** the grid's RecordSOurce until later, you need more checks before you just GO tnRecNo
GO tnRecNo IN ( lcAlias )
IF DELETED( lcAlias )
  RECALL IN ( lcAlias )
ELSE	
  DELETE IN ( lcAlias )
  *** Must do a TableUpdate as soon as the record is deleted. Otherwise,
  *** when it is recalled, you will get a PK violation 
  IF ! TABLEUPDATE ( 0, .F., lcAlias )
    MESSAGEBOX( 'Unable to Update Table', 48, 'So Sorry!' )
  ENDIF	
ENDIF
SELECT ( lcAlias )
COUNT TO lnRecCount FOR NOT DELETED()
lnItemno = 0
SCAN FOR NOT DELETED()
  lnItemno = lnItemno + 1
  REPLACE Itemno WITH lnItemno
ENDSCAN
THISFORM.TEXT13.VALUE = lnItemNo
This code goes in the grid's Deleted) method. No other code should be in the deleted method():
LPARAMETERS nRecNo
This.DeleteRecord( nRecNo )
NODEFAULT
The parameters statement should already be there.

As you are probabaly beginning to realize, this is not the best way to delete records from the grid. It would be much easier to have a delete button on the form and use that to delete the records.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform