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 derfloh 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

 
Tamar's point was that you should first check that the timer is actually firing. By generating a message that includes the time of day, you can monitor the frequency of the timer.

If you're satisfied that the timer is firing as expected, you should look for other causes of the problem. You could check that the SetFocus code works if you run it from the Click of a button, for instance.

Also, check that the other application is in fact updating the table. If the table is buffered in the other app, it could be that the changes haven't been written to disk at the time you do your SetFocus.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
the other application is in fact updating the table. that i've verified.

the timer seems to b firing only some of the time or it just 'dies'. any suggestions??

 
whole app does not hang, just the timer is not working anymore. It seems to work at th beginnging then the timer doesn't work anymore. uugghhh, what do suggest?

 
In the Timer event; instead of setting the focus, put

Thisform.mygrid.refresh

The setfocus() does not always refresh the grid if the grid is the only object in the form, the grid will always have the focus...
 
one issue remains: Even if grid.refresh() does better in refreshing the control, depending on your rowsource, you may not see new records unless you also refresh the alias. In your case (binding a table) it should work, but in case of a view you'd need a requery().

Also take a look at SET REFRESH, this is about refreshing aliases with data from disk, not refreshing controls.

Bye, Olaf.
 
Imaginecorp,

I suggested SetFocus rather than Refresh partly because it's faster, and also you generally need to do it anyway in order for the updated data to show up. Perhaps he should do them both, just to see if it solves the problem.

That said, if I've read this right, the SetFocus is working; it's just that the timer is not firing.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Mike;
Strange the timer is not firing, I have never seen a timer fail, use it every night on the server to "refresh" databases etc.

Olaf;
he says the table is updating but I wonder if he has the table in the DE, and is checking the other app (updating app) to see if the table is updated.

Friend01;
If the table is in the Forms DE, remove it and make sure the form is NOT in a Private Datasession, Refresh the grid via the Timer and lets see if it solves the problem
 
Friend01,

We really need to establish whether the problem is the timer or the grid.

Can you put some code in the timer to demonstrate whether or not it is firing -- perahps the DEBUGOUT as suggested by Tamar. Or even simply display a message on the background screen.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
OK, here are answered questions:

timer enables=.t. (YES)
interval >0 (YES)

grid is the only object in the form (YES)

should I use the 'set refresh' with some setting as Olaf suggests?

I will do the 'set focus' & as well as the refresh (both of them). Se new code in timer below.

The table is in the DE. According to form (right clic, properties), I am in the "default data session" (not the private data session).

I put some 'dummy' code in the timer to see if it's firing. ( I simply put "? 'Hi'") and I see it in the form in the back. So, the timer is firing but i seems that (as I mentioned) it works for a little while then the timer dies.

I now have the following in the Timer:

THISFORM.grid1.SetFocus
THISFORM.grid1.REFRESH
THISFORM.Refresh

What can be the problem?
 
Can we back up a bit? What do you mean by "the grid does not refresh"?

Could the grid be refreshing but the rows are not visible? That's a different kettle of fish.
 
OK, I think I know what's happening (and danfreeman I think this has to do what what you just said). I don't know why it's happening because the code in the timer should take car of it but it's not.

I did some troubleshooting and it seems that the file goes to EOF after a do a 'scan-endscan' in that timer. My Timer code "after debugging" and trying to figure out what's going is as follows:

THISFORM.grid1.SetFocus
SELECT tticket
SET DELETED ON
SET ORDER TO
GO TOP
THISFORM.grid1.REFRESH
THISFORM.Refresh
SCAN FOR DATE()>dateupd
REPLACE needupd WITH .T.
IF tticket.sentremail =.F.
DO updemail
REPLACE tticket.sentremail WITH .T.
ENDIF
ENDSCAN

I tried it without the 'scan-endscan' part and it doesn't go to eof in the status bar and the bottom of the vfp screen (which is what I want as I want to see all records). If I don't put the 'scan-endscan' in my timer code, the pointer does not go to eof (which I assume would be causing all these problems).

Now, correct me if I'm wrong but shouldn't the 'go top' make it go back to the top on every time. It's weird because from I can 'see' it's not going back to top. Can this be the problem? What do you think about my theory? How can I correct that?

please let me know.


 
to what value have you set the interval? If it's a small interval it could be a problem of the refresh needing too much time. Try this in the timer:

Code:
this.enabled = .f.
thisform.grid1.refresh()
thisform.grid1.setfocus()
this.enabled = .t.

That said I never needed a timer to refresh a grid and instead of asking, simply read the help on SET REFRESH and try it.

Bye, Olaf.
 
correct me if I'm wrong but shouldn't the 'go top' make it go back to the top on every time

I will and you are. GO TOP does move the record pointer to the first record, but you then do a SCAN/ENDSCAN which takes it to the bottom.

Also, I have to say that you've shifted the goalposts by a couple of miles. Suddenly, you're no longer displaying data in the grid; you're also updating it. The whole thing is now more than just a simple refresh.

Perhaps we can start at square one. Can you just tell us what you want to achieve.

__________________________________
Mike Lewis (Edinburgh, Scotland)

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

OK, let's start at square 1 as you mentionned. In my grid, I have 8 fields (the fields tticket.needupd & tticket.sentremail are not show in my grid to the user. They are just flags I use for other stuff) so I'm not 'updating the grid' per say. The data displayed in the grid is updated by another app. the only code I have with this grid are 'the timer code mentionned' and 'dynamicfontbold' and dynamicforecolor' set in my grid with an "iif" statement. what happens is that acoording to my timer code (the scan-endscan) I flag tticket.needupd WITH .T. according to my condition in my scan-endscan which in turn triggers my dynamicfontbold & dynamicforecolor' (therefore making the row color different and bold.

woudld what I mentionned in my previous post cause a problem? let me know if there's anything else.

F1

 
hmmmm, I'm wondering if a simple solution is to haev 2 timers. 1 for the:

THISFORM.grid1.SetFocus
SELECT tticket
SET DELETED ON
SET ORDER TO
GO TOP
THISFORM.grid1.REFRESH
THISFORM.Refresh

which does it every 5 seconds

and the other for the:
SCAN FOR DATE()>dateupd
REPLACE needupd WITH .T.
IF tticket.sentremail =.F.
DO updemail
REPLACE tticket.sentremail WITH .T.
ENDIF
ENDSCAN

which does it every 30 seconds.

what do you think? I'm not sure about multiple timers though.

An suggestions?

 
It doesn't matter if you don't display the flag fields in the grid, but only use them to format and color grid rows, the alias must be refreshed for that to take effect. And so for the third time, take a look at SET REFRESH. Especially as it's another app updating the flags. You need to load that updates in the form displaying the data in the grid.

Bye, Olaf.
 
Friend,

If one timer doesn't work, I can't see why adding a second timer will improve matters.

The fact that you are using DynamicXXX properties means that you do need to refresh the grid. These properties only take effect on a refresh. I didn't know you were using Dynamic properties when I told you that a SetFocus was sufficient.

You should also take note of what Olaf says about SET REFRESH. However, I'm not convinced that's the entire solution. I just did a quick test, and got the same result with REFRESH set to 0 and 2, that is, the grid displays the new value, but only after you give it focus.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

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

OK, so I just want to make sure I put it in the right place and in the right order. In my timer, I simply have to put the code as follows:

THISFORM.grid1.SetFocus
SET REFRESH to 2

correct?

please let me know.

thanks,
f1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top