Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Ken Murphy
  Where is Ken Murphy?
 Springhill
 Canada
 Ken Murphy
 To: solomon sackey
  Where is solomon sackey?
 texas
 Texas - United States
 solomon sackey
 Tags
Subject: RE: grid returns header1,header1 as headers
Thread ID: 143342 Message ID: 143346 # Views: 1 # Ratings: 0
Version: Visual FoxPro 6 Category: Grids
Date: Tuesday, August 28, 2007 6:20:01 AM         
   


> Dear Expert,
>
> I keep having this bug header1,header1... to replace the original column headers of a grid,after pressing the save button, which has this additional line
>
>
Thisform.activate

>
> Pls assist

Solomon,

Lets see if I have your problem correct. You created your grid, probably based on a query of some sort. It displays correctly (including your headers) but the first time you go to requery, your headers dissapear.

Here is what happens. When you requery, the first thing that VFP does is delete the existing cursor. The SELECT query is re-run and your cursor is recreated. The problem happens when VFP deletes the existing cursor. As soon as that cursor is deleted, your columns no longer exist. No columns means no headers. Your cursor is recreated and you get your columns back, but where does it get your headers from? It has already lost those.

Here is how you fix it. You are using VFP 6 so you will have to work a little harder than you would if you were to upgrade to VFP 9. Start in your form's .Load() and create a cursor that will look exactly like the result of your existing query.
CREATE CURSOR MyGridCursor (Field1 I, Field2 C(20), ... Fieldn L)
* If you were using VFP 9, you could use a SELECT statement with the READWRITE clause

* If you wish to give the user the ability to re-sort the grid by clicking on a grid header
* add the indexes you will need here:
INDEX ON Field1 TAG Tag1
INDEX ON Field2 TAG Tag2
...
INDEX ON Fieldn TAG Tagn

This gives you an empty readwrite cursor with any indexes you might need. An empty cursor is not worth too much, so you will need to fill that cursor with some data. Create a custom form method called .RepopulateGrid() or what ever and add this code:
* query the database to find the data you need and store it in a temporary cursor
SELECT Table1.iSomeField AS Field1, ;
       Table2.cSomeOtherField as Field2, ;
       ... ;
       Table1.lAnotherField AS Fieldn ;
   INNER JOIN Table2 ON Table1.FKField == Table2.PKField ;
       ... ;
   WHERE llWhatEverConditionsYouNeed AND ;
       ...
   INTO CURSOR Junk
SELECT MyGridCursor
* get rid of any data that may exist in your grid cursor
ZAP IN SELECT([MyGridCursor])
* Now populate your grid cursor with the data you just queried
APPEND FROM DBF([Junk])
* you don't need the junk cursor any more so get rid of it
USE IN SELECT([Junk])
* Refresh the grid
WITH ThisForm.MyGrid
   .SetFocus()
   .Refresh()
ENDWITH

Finally, in your Form's .Init(), set up the rowsourcetype, rowsource, column control sources, etc. or you can do it visually. Were you to do it in the .Init() it would look like this:
WITH ThisForm.MyGrid
   .RowSourceType = 1 && Alias
   .RowSource = [MyGridCursor]
   .ColumnCount = n && how ever many columns you want
   .Column1.ControlSource = [MyGridCursor.Field1]
   .Column2.ControlSource = [MyGridCursor.Field2)
   ...
   .Columnn.ControlSource = [MyGridCursor.Fieldn]
ENDWITH


Finally, when you want to requery, you simply issue a call to that repopulate method:
ThisForm.RepopulateGrid()

This is what I call a "grid cursor" and what Andy calls "Safe Select." (Wish I could come up with cool names like "Safe Select.") The idea here is that your rowsource cursor never gets deleted. It may become empty for a time, but it is never deleted. If the cursor is not deleted, your columns do not dissapear and if your columns don't dissappear, neither do your headers.

The problem you are experiencing has further ramifications. What happens if you have a textbox in the first column of your grid and in the textbox's .Valid() you add a bunch of validation code. If you do not use a grid cursor, not only will your headers dissapear, your validation code will dissapear too. Safe Select/Grid Cursor is the only way to go. For more information on this, go to the Foxite Community Weblog and look up Andy Kramek's blog on "Safe Select."

LATER

I just read your edited post. What are you doing in the .Activate()?? From what you are saying, Safe Select/Grid Cursor will definately provide a cure.

Ken
You shall know the truth - and the truth shall set you free. (John 8:33)

ENTIRE THREAD

grid returns header1,header1 as headers Posted by solomon sackey @ 8/28/2007 5:29:26 AM
RE: grid returns header1,header1 as headers Posted by Ken Murphy @ 8/28/2007 6:20:01 AM
RE: grid returns header1,header1 as headers Posted by Vladimir Zhuravlev @ 8/28/2007 6:26:19 AM
RE: grid returns header1,header1 as headers Posted by Ken Murphy @ 8/28/2007 6:29:30 AM
RE: grid returns header1,header1 as headers Posted by Cetin Basoz @ 8/28/2007 2:31:20 PM
RE: grid returns header1,header1 as headers Posted by Ken Murphy @ 8/28/2007 4:02:48 PM