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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to reset the values on a grid and repaint the grid back w/o values but show the grid lines back 3

Status
Not open for further replies.

titoneon

MIS
Dec 11, 2009
335
US
Hi guys
i have a form that has a grid(grid1) and a command button to Reset the content of the grid, the problem is when i click on the reset button, the grid is shown but it just the frame of the grid, it does not show the grid lines, it will only show the grid lines again after a pass values to it using the 'Thisform.txtTextBox.Value' which is inserted into cursor 'jobnos' then later displayed in Grid1
but when i want to clear the grid1, i use the below code to reset it.
Is there anyway to refresh the Grid and show it with the grid lines again ? Thanks a lot, by the way if visible=.T. it shows only the frame.

SELECT jobnos
USE
CREATE CURSOR jobnos (job_no C(6))

WITH Thisform.grid1
.Visible = .f.
.refresh
ENDWITH

Thisform.txtTextBox.Value=''
thisform.txtTextBox.SetFocus()
thisform.Command4.Enabled=.f.
Thisform.Refresh()




 
but when i want to clear the grid1...

A Form's Grid has a RecordSource (a Cursor or a Table).

That RecordSource Cursor (or Table) cannot be 'destroyed' without causing the Grid to 'mis-behave'.

Code that will NOT Work:
Code:
SELECT jobnos
USE  && <-- Original Form Grids RecordSource is 'Destroyed' here
CREATE CURSOR jobnos (job_no C(6))

When you create a New Cursor, you need to 'destroy' the original one and build a new one.
That will not work with a Cursor that is a Grid's RecordSource.

With an Grid's EXISTING RecordSource Cursor/Table you can set Filters and/or Indexes to make the record values no longer appear in the Grid, but you cannot 'destroy' and re-build it.

One method of code that will likely work:
Code:
SELECT jobnos
DELETE ALL
SET FILTER TO !DELETED()

Is there anyway to refresh the Grid

The command to do this is (in general): ThisForm.Grid1.Refresh

Good Luck,
JRB-Bldr


 
Hi JRB-Bldr,
That worked, i thou that closing the cursor and redoing by implying "*CREATE CURSOR jobnos (job_no C(6))" will rebuild it and bring the Grid back as it is suppose to be but well i was wrong, thanks for the lesson.
Regards
 
Hi,
according to my experience you have to reset the grid resource too.

.recordsource = "jobnos"

However, it can destroy to column formatting so running column formatting procedure is usually needed.

I use it when deleting records from dbf and want it displayed instantly in the grid after the PACK command closes the dbf and I reopen it.

Mat
 
The best thing to do is never close the grid cursor, nor set recordsource="" and back to the cursorname, but ZAP the cursor and append new data.

That of course means you don't bind the grid to anything you won't want to ZAP, eg you don't bind it to a table directly.
Well, if you do, you obviously don't ZAP, but you can eg SET FILTER TO .F. to display no data of the DBF.

Bye, Olaf.
 
Hi Guys,
This is what exactly did in the reset Butt.

SELECT jobnos
DELETE ALL && this rebuild the grid again as it suppose to be
SET FILTER TO !DELETED() && this rebuild the grid again as it suppose to be
zap
thisform.container1.Refresh
WITH Thisform.grid1
.Visible = .t. && this show the grid
.refresh()
ENDWITH
 
There's no reason to DELETE and then SET FILTER if you're going to ZAP.
 
ZAP eliminates all existing records, but does not 'destroy' the cursor

If you use the ZAP, then you do not need to do the
Code:
DELETE ALL
SET FILTER TO !DELETED()

I have had varying success using ZAP and Grids, but it could be that something else was actually causing the problems.

Go ahead and try it for yourself and see if it works for you. It should work.

Also note that you should not need to use the following after having issued ThisForm.Grid1.Refresh
Code:
WITH Thisform.grid1
.Visible = .t. && this show the grid
.refresh()
ENDWITH

Good Luck,
JRB-Bldr

 
Your code has been reviewed and you have some tipps. For sake of a good sleep, by all means do not ZAP without specifying the alias to ZAP. Sometimes you might ZAP the wrong workarea.

Instead:
ZAP IN jobnos

Actually that's the only line you need. Perhaps also Grid.Refresh(), but not more.

Bye, Olaf.
 
Hey Guys,
when i posted the code, i just realized that ZAP command takes care about it and "delete all" was not needed, but it was late to edit that post, also, yes at that point the only workarea open is "Jobnos" so anyway thanks for the advise, thanks to all.
I will post another question, it is related to what i am working but i think the subject should be different, it is about using in vfp 9.0
the "COPY TO " to create an excel spreads file with extension xlsx, so i will post later.
Thanks
 
>the only workarea open is "Jobnos" so anyway thanks for the advise.

Sorry for getting on your nerves about this.

I dont't doubt "the only workarea open", but this is the situation now on august 21st, 2013 and in this form with this grid. You introduce a habit and you shouldn't. You obviously need to lower security by SET SAFETY OFF, if you want to use ZAP without user intervention, but you can lose data of a DBF then, too. Some people for example don't know that the grid has a misbehaviour to activate it's recordsource alias without any SELECT xyz code, and even less know that is the reason you need to set focus to an off grid control to be able to REPORT FORM on a different alias than shown in a grid. Never ever be so sure about anything.

If you're nerdy you would do:
Code:
lcAlias = "jobnos"
IF UPPER(JUSTEXT(DBF(lcAlias)))=="TMP"
   Set Safety Off
   Zap In (lcAlias)
   Set Safety On
ENDIF

This is checking for TMP file extension to ensure the workarea to ZAP is just a cursor. This is using lcAlias to ensure you don't by accident use different alias names in the file extension check and in ZAP. This is setting safety off temporarily, only. I'm skipping to make it even more complicated with TRY..CATCH. But please, don't be so lazy to only ZAP. If you want the code more generic, make it a grid method and ZAP IN (This.Recordsource), or set lcAlias = This.Recordsource using above code.

Bye, Olaf.
 
Olaf,
I will do that, thanks for been such a great guy, i will create a method and put that code there.
Thanks again, i will post my other question right away after this, please excuse my minimun experiences by asking about the next post, i hope i can find the answer.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top