Hackers Guide to Visual FoxPro 7.0
RecordSource, RecordSourceType
These two properties determine what table or cursor provides the data for a grid. RecordSourceType, which tells the grid what kind of object to get its value from, offers the expected choices plus one really strange one. RecordSource identifies the particular item that provides the grid data.| Usage | grdGrid.RecordSource = cSource cSource = grdGrid.RecordSource grdGrid.RecordSourceType = nSourceType nSourceType = grdGrid.RecordSourceType |
| | With RecordSourceType set to 2-Prompt, if no table is open in the current work area you're prompted to choose one, but if the table you choose is already open in another work area, the grid doesn't get filled at all—it consists of just a thin black outline. We can't think of any situation in which that's the desired result. |
If you get prompted and the table isn't already open, it's opened and used for the grid.
We were pleased by the addition of SQL Statement to the list, but we're still hoping the list of RecordSourceTypes will be enhanced down the road. The one we'd really like to see there is Array, but we bet the creative folks who gave us 10 choices for list and combo RowSourceType can come up with some more, too. Once you've chosen a RecordSourceType, filling in RecordSource is pretty simple.| | If you do something that closes the RecordSource of a grid (like rerun the query that created it), the grid clears out. All you have is a rectangle in the grid's BackColor. If you re-create the cursor or reopen the table, you have to reset RecordSource to the cursor (or SQL statement) to refill the grid, but any column-level changes you've made (like header captions or column widths or ColumnCount) are lost for good. This is another case where a view is a better choice. |
There is a work-around (read: trick) you can use to prevent all your changes from being lost. Instead of just resetting RecordSource, first set it to the empty string, then do whatever table manipulation you need to do (close and reopen a table, run a query, whatever), then reset RecordSource to its original value. However, if you've set the ControlSources of the individual columns to something other than the default (that is, the same-numbered field in the table), you have to save the ControlSources and restore them afterward, too.
| Example | This.RecordSourceType = 0 && Table This.RecordSource = "Employee.DBF" |
| See Also | Grid, RowSource, RowSourceType |
View Updates
Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.
Категории