×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

how to clear the grid data
2

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.

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??












RE: how to clear the grid data

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

RE: how to clear the grid 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). 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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close