Search code examples
recordsvisual-foxprogridcontrol

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.


Solution

  • 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.