Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss. print.
GRIDWORKS: OPEN A NEW RECORD AFTER CURRENT RECORD IN GRID

Overview
You need the ability to add a new record in a grid without it moving to the bottom of the table visually. In other words, you want to click on a record in a gird, click an add button and insert the record right after the record you selected prior to clicking the add button. I have ran into this several times in applications I have written; have been posed this question twice in the forum, a couple of times dealing with emails with programmers, and a few times on one-to-ones with programmers. VFP's grid control does not support this featureā€¦ so here is the work around.

Workaround
This has come up before and you need a field added in your table, called Recnbr(Integer) as a regular index key. So add this field into the table, probably at the end of your table fields. It's default value in the DBC is Recno(), which only happens when you add a record. This is the index order needed within your form's data environment to be set as the cursor's order, thus now applied to the grids record order within the grid. When you add a record you must have your cursor on a particular records in the grid, then on your add command button issue code like this:


nRecnbr = RECNO()
INSERT INTO clients (RECNBR) VALUES (nRecnbr)
=TABLEUPDATE()
Thisform.Grid1.Refresh
Thisform.Grid1.Column1.SetFocus

You will see this opens up a blank record within your grid right after the record in the grid that had the focus prior to you clicking the Add command button.br> This is a work around that may work for you. Let me know if this does? You must keep your index order set to this Recnbr index for this to function correctly. So do not change it within the form. If you do change the order, place it back to this default order after working within the form and issue a grid refresh prior to attempting using the add command button.

To assist you in seeing what I have done, I have included a zipped file called Gridworks-1 with the project and very basic source. Just run the form called Gridworks1 and click into the second record, then click on the Add command button. You will be able to add the record in the middle of things in the grid.

This is a very basic project, but applied in theory what you may wish to do in these isolated cases.

As with all so-called work around (compromises); since you have issued a =TABLEUPDATE() in the add command button, if you wish to use =TABLEREVERT(); well too late. You must delete the record to get ride of it. In cases like this I either remove the Table Revert command button off the form and force the user to delete the record, or replace the TABLEREVERT() with code that does an actual delete. To the end user the visual aspects are the same.

As with most things in VFP, always a way - LOL.

Download code
Click here to download the code that is discussed in this article. The download is a zipfile. Its size is 6,718 bytes.

ABOUT THE AUTHOR: PETE SASS

Pete Sass Pete has worked in the computer world since the late 70's. He loves the outdoors and lives in a small town called Marathon, in the north of Canada.

FEEDBACK

GUNTUR @ 12/16/2009 3:29:35 AM
GUNTUR

GUNTUR @ 12/16/2009 3:30:07 AM
GUNTURS



Your Name: 
Your Feedback: 

Spam Protection:
Enter the code shown: