Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Grid question
Message
 
To
14/12/1999 11:40:51
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Title:
Miscellaneous
Thread ID:
00303412
Message ID:
00303469
Views:
19
I have been doing something similar, using the AfterRowColChange event. Here's the code I used:
* When new row added, fill in Order ID and Line_ID in OrderItems table
IF orderitems.order_id <1		&& New item?
	lnNewRec = recno('orderitems')   && keep track of where we are
	IF RLOCK('0','setup')
		lcKey=SETUP.orderitem			&& get orderitems key
		REPLACE SETUP.orderitem WITH lcKey+1		&& create key for next time
		UNLOCK
	ELSE	
		?? CHR(7)          && still under development
		WAIT WINDOW ' Could not lock setup record.  Please try again. ' NOWAIT
		SELECT Orders
		RETURN .F.
	ENDIF
	REPLACE orderitems.KEY WITH lcKey    && use orderitems key
	lnOrderID= orders.order_id
	REPLACE orderitems.order_id WITH lnOrderID	&& fill in order ID
	lnItem=1				&& Find last item #
	LOCATE FOR orderitems.order_id=lnOrderID .AND. orderitems.line_id=lnItem
	DO WHILE FOUND()                       
		lnItem=lnItem+1
		CONTINUE
	ENDDO
	GOTO (lnNewRec)
	REPLACE orderitems.line_id WITH lnItem	   && Insert item number in new record
ENDIF
THISFORM.REFRESH()
I'm still working on improvements, most notably using a newid() function as used in the TasTrade sample database. That would remove the RLOCK() sequence and might avoid some multiuser problems I've run into.

Also, when using foreign keys, watch out for table buffering. I initially forgot to disable buffering on my Setup table and had all kinds of problems with duplicate keys.

You might wish to create a custom property on the form that holds the record number of the current grid item, then test it to see if you are on a newly added record. If you are buffering the table, the new records will have negative numbers until you do a TABLEUPDATE.

If anyone else has any recommendations or corrections regarding my above code, I would be pleased to read them. I'm still early in the learning curve, myself.

Good luck,
Neil Preston

>I need to allow users to add records in a datagrid. I have set the allow add new proprty to .T., but I need to capture the insert to ensure foriegn keys are correctly set. Which event do I need to capture? I do not want to run a function unless I need to, such as when the user has only edited the existing record, only capture the add new record event and process.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform