Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to clear the grid data 2

Status
Not open for further replies.

Bhashi

Programmer
Sep 13, 2022
15
LK
I have a grid as Grid1 and the columns are as below.
Code:
Code   Qty         Data
520B   100         02/05/2022
521B   300         02/05/2022
522B   500         02/05/2022
I want to clear the grid data when I'm click on the clear button. how can I do this??












 
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.

Chriss
 
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)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top