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

Problem displaying data in a grid - VFP6 SP5

Status
Not open for further replies.

JLF999

Programmer
Jul 11, 2016
6
US
I am using a table as the record.source for a grid and the record source type is set to 0.
The control source for each of the columns in the grid are set to the respective fields in the record source table initially.
I say initially because when I run the form the following happens 1. no data is displayed even though there are records in the table and 2. When I go back an look at the properties for the grid columns the control source is now 'none'.

This is quite frustrating to say the least and a little embarrassing as I worked with VFP and used to know how to do this but have been away from it for several years and just recently picked it up again.

What am I doing wrong?
 
Hi JLF999,

please try the default value for RecordSourceType = 1 (Alias)

Regards, Stefan
 
First, are you sure you want the RecordSourceType to be 1? With that setting, the grid will look for the table on the VFP search path, and open it if it is not already open. That could cause problems if the table can't be found or can't be opened for any reason. It's more usual to open the table first (either implicitly with the USE command or via the Data Environment), then set the RecordSourtType to 1, and set the RecordSource to the table's alias.

That said, I don't think that would explain the behaviour you are seeing. You seem to be saying that the ControlSource settings disappear at design time. I can't see how that can happen, assuming you correctly set the ControlSources and saved the form in the first place.

A more likely possibility is that the underlying table is getting closed while the grid is visible - or between instantiating the grid and it first becoming visible. That would result in the all grids' columns losing all their properties, including the ControlSource, resulting in a completely blank grid. If that's the case, the solution is to make sure that the table doesn't get closed. Use RecordSourtType = 1, and if necessary create a cursor for the RecordSource that you can keep open all the time. But that wouldn't explain the properties disappearing at design time.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

You wrote: "First, are you sure you want the RecordSourceType to be 1?"

Do You really mean "... to be 1?" or do You rather mean "... to be 0?"

Regards, Stefan
 
Hi Mike,

OK - my world is back in order :)

- therefore I also have suggested: RecordSourceType = 1 (Alias)

In my VFP-Apps I have many, many grids.

First I always add the necessary table / tables to the data environment (design time). Then I set the grid properties (also design time):

.RecordSource = "customer" && for example
.RecordSourceType = 1

So VFP will open and close all the necessary tables automatically.

I have never used a USE command for a grid - and this works very well all the time for me.

PS: in EVERY form I set .DataSession = 2 (Private Data Session)

Regrads, Stefan
 
> When I go back a look at the properties for the grid columns the control source is now 'none'.
At runtime? At design time?

If at design time, there's nothing at runtime changing the SCX or VCX, so it would already have been that way before, that's normal and doesn't cause the grid go blank. Indeed, when you only set the RecordSource the columns ControlSource only is set at runtime. Column1,2,3... of the grid will simply display field1,2,3... of the table or alias and CcontrolSources will reflect that at runtime only.

If you have no values as ControlSource at runtime, then most probably you somehow changed the RecordSource and even if you set it back, your grid is blanked.

As you bind to a table directly that's rather hard to break in that way, as you don't have the need to change the RecordSource at any point, to limit what's seen you rather SET FILTER than anything else. The safe select mechanism isn't necessary in that case, though it performs better in most cases, especially if you have a large table and start with a default filter only fetching a small part, like last month data, the details of the first project/customer/user or whatever other parent entity. Any default filter that limits the data to a sensible amount.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top