how to clear the grid data
how to clear the grid data
(OP)
I have a grid as Grid1 and the columns are as below.
I want to clear the grid data when I'm click on the clear button. how can I do this??
CODE
Code Qty Data 520B 100 02/05/2022 521B 300 02/05/2022 522B 500 02/05/2022
RE: how to clear the grid data
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.
Chriss
RE: how to clear the grid data
If that's not what you want, I would favour setting a filter on the underlying cursor (or table). SET FILTER TO .F. would be sufficient. Again, you need set focus to the grid to see the change take effect.
Mike
__________________________________
Mike Lewis (Edinburgh, Scotland)
Visual FoxPro articles, tips and downloads