>Hi All,
>
> I just wanted to share an experience that I've recently had concerning Grids and the RECORDSOURCE property. I constructed a Table Maintenance Form which had 2 Tab Pages. The first Tab Page has a Grid of all the records in the table and the second Tab Page has the fields from the current record. I have a Property called MaintAlias in the Formset which holds the name of the Table that is to be maintained and I use this Property to set the RECORDSOURCE for the Grid in the ACTIVATE Event of the Formset. I used the Grid Builder to arrange the fields in a specific order. After I ran the form I noticed that the Grid headers didn't match up to the data in the
>corresponding Grid fields, one field had even split over two Grid columns. I checked the Table to make sure that I'd entered data in the correct fields, and it was fine. I couldn't figure out what was happening. I then commented out the code that set the RECORDSOURCE and the Grid worked fine.
>
> Has anyone else encountered this problem? It seems that VFP6.0 doesn't like a Grid being built with a Builder and then having the RECORDSOURCE specified when the Form is invoked.
>
> Is it a bug or am I just doing it the wrong way?
>
>Gavin...
Gavin,
If you want to change recordsource in code first decide if you want to preserve column formatting or not.
-If you are gonna preserve formatting :
Grid.Recordsource = "" && Set it to nothing first
* Do whatever you would do with source
Grid.Recordsource = "myTableOrCursor" && Set recordsource
If you do it directly then you get weird results.
-If you won't preserve formatting
Grid.Recordsource = "" && Set it to nothing first
Grid.ColumnCount = -1 && Reset all columns
Grid.Recordsource = "myTableOrCursor" && Set recordsource
Headers wouldn't match the table naturally because a grid binds its columns with field order if not specified in code. I suggest if you're changing recordsource and columns do not match field order :
-Either first save current columns.controlsources to array before blanking recordsource and reassign using array info.
-Or set column.controlsources in code.
Cetin