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

Grid doesn't always refresh

Status
Not open for further replies.

friend01

Programmer
Jun 4, 2009
94
CA
Hi,

I have a problem with my grid where it doesn't seem to 'refresh' properly all the time. I'd say about 80% of the time it works fine but 20% it doesn't. I know it's a 'refresh problem' because if I open & close the app it appears correctly. I have to following specs:

data environment - 1 dbf with a filter to 1 field

in my form specs are as follows:

init method:
This.Show()
READ EVENTS


load method:
SELECT the dbf
SET DELETED ON
SET ORDER TO
GO TOP
THISFORM.REFRESH()



any hel on this ongoing enigmaitc problem. why is it that the refresh doesn't work? is there somehitng I should pu in the refresh method? IS there a timer I should put with something in it to 'force refresh'?

any help please.

thanks,
F1

 
OK, so I'll try putting the
ThisForm.grid1.Refresh

in the init method, BUT do I put it after :
This.Show()
READ EVENTS

or before it
or between This.Show() & READ EVENTS ?


 
Hi friend01,
Init and Load are events and are not methods.
Put this line where you want in Init event.
 
Also, I have a question with regards to your suggestion. Isn't the "INIT" method only 'launched' 1 time and that's once the object is created and that's it (from my understanding). I just want to understand that concept . let me know if i'm right in saying so.

thanks, f1
 
ok, so where exactly as I asked do i put that?
ThisForm.grid1.Refresh

in the init event, BUT do I put it after :
This.Show()
READ EVENTS

or before it
or between This.Show() & READ EVENTS

??
 
I'm surprised your form works at all if you really have READ EVENTS in the init method.

Nothing happens after READ EVENTS, so your form shouldn't even finish initializing. READ EVENTS belongs in the program that calls your form, not in the form.
 
Friend,

Like Dan, I'm surprised it works at all. Apart from the READ EVENTS issue, putting a Refresh in a Load event is completely useless, because the Load fires before any of the controls are instantiated, so there's nothing to refresh at that point.

But, most important of all, you don't say anything about how or where you are populating the grid. Where are you setting the RecordSource and RecordSourceType? And under what circumstances does the grid need to be refreshed?

Perhaps if you could start by describing exactly what you are trying to achieve, we can point you in the right direction.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
grid is populated thru right click on grid & go to properties. at the recordsource I have the dbf name.


 
FYI, if I put the 'read events' in the prg that calls my form I get a completely white screen (no form, no grid, no nothing at all).
 
ok, so i managd ot get my form & grdi to appear as now I have the 'read events in my prg that calls my form.

my prg is as follows:
Set talk off
* All settings here.
Do form mainform
read events

now in my form.init I have:

This.Show()

in my form.load, i have:
SELECT the dbf
SET DELETED ON
SET ORDER TO
GO TOP

you think that will make it always force a refresh?

let me know
JJ


 
You don't need *any* of that code. Anywhere.

It won't accomplish anything the form/grid doesn't already know how to do on its own, unless there's additional code you're not showing us.
 
JJ,

It's looking a little better.

Your main program is OK.

But you don't need This.Show() in the form's Init. The form will become visible in any case at the end of the Init.

In the Load, the SET DELETED is OK. I'm not sure why you are selecting the DBF, and doing the SET ORDER and GO TOP there, but it won't do any harm.

The important point is the setting of the RecordSource and RecordSourceType. If you do that at design time, then the grid should work correctly, provided the DBF is open when the form is launched. Alternatively, you can set RecordSource and RecordSourceType programmatically, in either the form's Init or the grid's Init.

One thing you haven't told is why you think you need to refresh the grid. You normally only need to do that if the underlying data changes. If you simply want to display a fixed set of data in the grid, there's no need to refresh.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Hi Mike,

Thank you very much, I apprecate the time you're takibng. The data in the dbf is changed by another app that the user has to 'edit info'.

The reason I want to refresh the grid is that I want to make sure that the info in the grid that is showing is always up to date so I want the grid to always have the 'current' info? can you help me ensure that.


thanks,
f1
 
F1,

If the grid is refreshed when other users update the DBF, you don't have to worry about refreshing when the form loads.

In fact, you don't need to refresh it at all. All you need to do is to set focus to the grid. When you do that, the grid will automatically show the changed values.

The only problem is knowing when to do that. One solution would be to add a timer to the form. Set the Interval property to a suitable value. In the Timer event, add one line of code:

THISFORM.MyGrid.SetFocus

If I've understood the problem correctly, that should be all you need.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Thank you Mike for all your time. It seems to be working. Hopefully this fixes the problem once and for all. Again, thank you so much.


F1
 
Hi Mike,

It just happened again. The grid does not refresh. I think there's something wrong with the Timer. I believe (from what I can tell) is that the timer dies. Could that be? Anything you know acn tell me about that?

let me know,

thanks,
f1
 
Debugging code involving a timer is a little tricky, but my suggestion for debugging is that you add this code to the timer's Timer method, so you can see what's going on:

* Put this at the top of the method
DEBUGOUT "In Timer method. About to refresh grid at " + TRANSFORM(DATETIME())

Then, open the Debugger, and run your test. What you should see is a series of lines in the debug output window, showing you each time the timer fired.

Tamar
 
there's really not much code to debug as the only line in the code is:

THISFORM.MyGrid.SetFocus


it's set to interval=10000 (every 10 seconds)

but the grid does not refresh.

any help?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top