A grid displays what data is in its recorsource. Usually that's a workarea, so a DBF or cursor or view - in the end a table of some kind.
The simplest way to clear the grid is to delete all data, but I doubt you want to lose data. Or is this discardable data? Then you can ZAP this recordsource workarea.
There are other ways, too. You can SET FILTER to a condition that has no data, you might have a view bound to the grid, which is parameterized. That would allow setting this parameter to something yielding no data, for example a view of receipt items ofa POS system could be using a view with WHERE receicptid=?m.receiptid and setting m.receiptid to a new, not yet used id and then REQUERY() would empty that view and thus also the grid.
And then you can always create a cursor of the same structure as the grid already displays, just empty. Then change the grid recordsource to that empty cursor, at least temporarily. It's the least probable solution as it does not lead to a workflow you can repeat indefinitely. Of course you can always switch to yet another empty cursor. But the grid is there for a purpose, isn't it, to display something, and it would make it harder to have simple code relying on the recordsource to always stay the same alias/workarea throughout the lifetime of the form.
So the usual solutions to an empty grid are surely a zapped cursor, not a DBF for persisting data permanently. Or a view, as suggested, or a FILTER.
What you can't have, actually, is an unbound and empty grid, when the grid is that, it is blank, it has no cells. It isn't a control like a textbox that can be used without binding data.
I can't add much to what Chris has already said, except to say that if you just want to clear the data from the grid without actually deleting it from the underlying table or cursor, you can simply set the grid's RecordSource to an empty string, and then set focus to the grid. But that would also mean that you would lose the columns, that is, the grid would just appear as an empty rectangle.
If that's not what you want, I would favour setting a filter on the underlying cursor (or table). [tt]SET FILTER TO .F.[/tt] would be sufficient. Again, you need set focus to the grid to see the change take effect.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.