Liviu Solcovenco
Liviu Solcovenco

Reputation: 85

GridControl Refresh

I have a grid control in vfp9 on a form. And I have a button witch deletes (with pack) the current record. After I delete the record the grid doesn't find the resource. It remains only an empty rectangle. I maked something like this: DELETE ALL PACK GO TOP thisform.grid1.Refresh

,but without effect. Thanks in advance.

Upvotes: 0

Views: 2453

Answers (3)

Swordblaster
Swordblaster

Reputation: 356

The VFP grid hates the recordsource being modified like that.

You need to disconnect your grid recordsource (ie, set it to ""), do your operations and then reset the recordsource and refresh.

Upvotes: 1

DRapp
DRapp

Reputation: 48139

As Tamar mentioned... pack is really bad in day-to-day activities. However, there is a "SETTING" that can "hide" records for you through all normal operations UNTIL a nightly handled administrative task to permanently remove the records...

SET DELETED ON
SET DELETED OFF

By turning "ON" (and it only has to be done once for the entire application, unless you are dealing with forms dealing with private data sessions, then it needs to be done there too. SET DELETED ON tells VFP to HIDE any records marked for deletion so they don't clutter the screen. It also keeps them hidden from any type of SQL querying too, so you don't get the records marked for deletion.

by SET DELETED OFF, will turn OFF the hiding and allow you to re-see any/all deleted records again. This, in case you accidentally marked a record for deletion and needed to "RECALL" it (undelete).

Now, all that said. If you mark the record for deletion, such as your set filter after finding criteria, doing a delete all, pack, that is bad...

All you should need in your button's click event is to

DELETE
Thisform.YourGridObject.Refresh()

and the record should be visually removed from the list. When you issue a PACK, it actually CLOSES the table, and thus unbinds itself from the grid, removes all deleted records, then re-opens itself via the cleaned version, but doesn't automatically re-bind itself to the grid.

Upvotes: 1

Tamar E. Granor
Tamar E. Granor

Reputation: 3937

The problem is that you're recreating the grid's RecordSource and it doesn't like that. Without knowing more about what you're doing, it's hard to offer specific advice. However, it's generally considered bad form to pack a table in normal application activities. Generally, PACK is reserved for administrative code that runs in off hours, since it requires exclusive access to the table.

What's your goal here? Why are you deleting all records in the table that a grid is based on?

Tamar

Upvotes: 1

Related Questions