Here is an interesting issue. I have a grid. I log transactions to the grid.
I do a grid.refresh after each record addition so that the grid refreshes.
This works well, except when traffic is heavy, cpu usage is very high due to
the grid.refresh being done 5 or 10 times a second, and the form controls
can become unresponsive, and incoming transactions can become queued up. If
I disable the grid.refresh, cpu is 5% and incoming transactions don't get
queued, all is well - except the grid does not get refreshed.

So I came up with a method that only refreshes the grid once or twice a
second to prevent excessive cpu usage. This works quite well except for one
issue. This is the tricky part.

If you add one record and do a grid.refresh, the record you just added
appears at the bottom of the visible grid. If you add more then one record
and do a grid refresh, the last record you added appears in the middle of
the visible grid, and the display of records jumps up accordingly. The next
record appears underneath this, the next under that, and so on until it gets
to the bottom of the visible grid. Then it jumps up again. I have a form I
can post if anyone wants to see an example.

Question - how can I add more then one record at a time and do a
grid.refresh AND have the last record appear at the bottom of the visible
grid?

Re: Grid and grid.refresh by trw7at

trw7at
Wed Nov 05 11:35:40 CST 2003

Ook seemed to utter in news:uQt90g7oDHA.744@tk2msftngp13.phx.gbl:

[snip]
> If you add one record and do a grid.refresh, the record you just added
> appears at the bottom of the visible grid. If you add more then one
> record and do a grid refresh, the last record you added appears in the
> middle of the visible grid, and the display of records jumps up
> accordingly. The next record appears underneath this, the next under
> that, and so on until it gets to the bottom of the visible grid. Then
> it jumps up again. I have a form I can post if anyone wants to see an
> example.
>
> Question - how can I add more then one record at a time and do a
> grid.refresh AND have the last record appear at the bottom of the
> visible grid?

If I understand you, what you are trying to avoid is the
grid seeming to sort of "jump around" as it's refreshed?
You want it to appear to nicely scroll as the new records
come in - with the most recently added record always on
the last displayed row of the grid?

This is actually pretty easy (once you get the hang of
programmatically scrolling the grid). Check out the
DoScroll method, the ActiveRow property and the RelativeRow
property on the grid. Then do something like this:

LOCAL llOldLock

llOldLock = ThisForm.Lockscreen
ThisForm.Lockscreen = .T.

SELECT theGridTable
GO BOTTOM

ThisForm.myGrid.SetFocus()

** scroll until the grid looks like you want
** this is left as an exercise for the 'student' :^)

ThisForm.Lockscreen = llOldLock

-- TRW
_______________________________________
My e-mail: t r w 7
@ i x . n e t c o m . c o m
_______________________________________

Re: Grid and grid.refresh by Ook

Ook
Wed Nov 05 12:39:12 CST 2003

> >
> > Question - how can I add more then one record at a time and do a
> > grid.refresh AND have the last record appear at the bottom of the
> > visible grid?
>
> If I understand you, what you are trying to avoid is the
> grid seeming to sort of "jump around" as it's refreshed?
> You want it to appear to nicely scroll as the new records
> come in - with the most recently added record always on
> the last displayed row of the grid?
>
> This is actually pretty easy (once you get the hang of
> programmatically scrolling the grid). Check out the
> DoScroll method, the ActiveRow property and the RelativeRow
> property on the grid. Then do something like this:
<snip>

This has potential. It also has one very serious shortcoming - ActiveRow and
RelativeRow only has a non-zero value when the grid has the focus. Setting
the focus to the grid can conflict with the user trying to enter information
into fields on the form when the refresh fires. I'll have to play with it
and see if I can work around that.



Re: Grid and grid.refresh by Ook

Ook
Thu Nov 06 09:30:28 CST 2003

I don't think this is a feasible solution. There are a few fields that the
user will need to edit from time to time, and having the focus jump to the
grid to do the refresh makes this impossible. Maybe I need an alternate
control of some sort. Something that I can keep 100 records in, and that
doesn't use excessive cpu on refresh, and/or will scroll smoothly. The VFP
grid is, and has always been, a kluge, and I try to avoid them when I can.
Any recommendations?

"Tim Witort" <trw7at@ixdot.netcomdotcom> wrote in message
news:Xns942A619FB1600timwitortwrotethis@207.217.77.205...
> Ook seemed to utter in news:uQt90g7oDHA.744@tk2msftngp13.phx.gbl:
>
> [snip]
> > If you add one record and do a grid.refresh, the record you just added
> > appears at the bottom of the visible grid. If you add more then one
> > record and do a grid refresh, the last record you added appears in the
> > middle of the visible grid, and the display of records jumps up
> > accordingly. The next record appears underneath this, the next under
> > that, and so on until it gets to the bottom of the visible grid. Then
> > it jumps up again. I have a form I can post if anyone wants to see an
> > example.
> >
> > Question - how can I add more then one record at a time and do a
> > grid.refresh AND have the last record appear at the bottom of the
> > visible grid?
>
> If I understand you, what you are trying to avoid is the
> grid seeming to sort of "jump around" as it's refreshed?
> You want it to appear to nicely scroll as the new records
> come in - with the most recently added record always on
> the last displayed row of the grid?
>
> This is actually pretty easy (once you get the hang of
> programmatically scrolling the grid). Check out the
> DoScroll method, the ActiveRow property and the RelativeRow
> property on the grid. Then do something like this:
>
> LOCAL llOldLock
>
> llOldLock = ThisForm.Lockscreen
> ThisForm.Lockscreen = .T.
>
> SELECT theGridTable
> GO BOTTOM
>
> ThisForm.myGrid.SetFocus()
>
> ** scroll until the grid looks like you want
> ** this is left as an exercise for the 'student' :^)
>
> ThisForm.Lockscreen = llOldLock
>
> -- TRW
> _______________________________________
> My e-mail: t r w 7
> @ i x . n e t c o m . c o m
> _______________________________________



Re: Grid and grid.refresh by trw7at

trw7at
Thu Nov 06 11:32:25 CST 2003

Ook seemed to utter in news:uBQNlrHpDHA.2964@tk2msftngp13.phx.gbl:

> I don't think this is a feasible solution. There are a few fields that
> the user will need to edit from time to time, and having the focus jump
> to the grid to do the refresh makes this impossible. Maybe I need an
> alternate control of some sort. Something that I can keep 100 records
> in, and that doesn't use excessive cpu on refresh, and/or will scroll
> smoothly. The VFP grid is, and has always been, a kluge, and I try to
> avoid them when I can. Any recommendations?

This is not an option?:

User in some other control does something that requires
the grid to be updated or some other non-user activity
requires grid update (perhaps within a timer event?)...

lock screen

record current control

update grid as discussed earlier

set focus to current control

unlock screen

A nice non-grid option that I have used makes use of an
editBox. I just keep appending lines to the editBox's
controlsource (a memo file or other text source). The
editBox is a natural for this kind of running display:

add lines to the text source

ThisForm.editBox.SelStart = LEN(ThisForm.editBox.Value)

-- TRW
_______________________________________
My e-mail: t r w 7
@ i x . n e t c o m . c o m
_______________________________________

Re: Grid and grid.refresh by Ook

Ook
Thu Nov 06 12:19:45 CST 2003


"Tim Witort" <trw7at@ixdot.netcomdotcom> wrote in message
news:Xns942B6112EF1F6timwitortwrotethis@207.217.77.201...
> Ook seemed to utter in news:uBQNlrHpDHA.2964@tk2msftngp13.phx.gbl:
>
> > I don't think this is a feasible solution. There are a few fields that
> > the user will need to edit from time to time, and having the focus jump
> > to the grid to do the refresh makes this impossible. Maybe I need an
> > alternate control of some sort. Something that I can keep 100 records
> > in, and that doesn't use excessive cpu on refresh, and/or will scroll
> > smoothly. The VFP grid is, and has always been, a kluge, and I try to
> > avoid them when I can. Any recommendations?
>
> This is not an option?:
>
> User in some other control does something that requires
> the grid to be updated or some other non-user activity
> requires grid update (perhaps within a timer event?)...
>
> lock screen
>
> record current control
>
> update grid as discussed earlier
>
> set focus to current control
>
> unlock screen
>
> A nice non-grid option that I have used makes use of an
> editBox. I just keep appending lines to the editBox's
> controlsource (a memo file or other text source). The
> editBox is a natural for this kind of running display:
>
> add lines to the text source
>
> ThisForm.editBox.SelStart = LEN(ThisForm.editBox.Value)
>

The form processes web transactions that come in 24/7. It's controlled by a
timer that runs every 40 milliseconds. This is always happening, and when it
does the grid gets updated. While this is happening, there a few textboxes
on the form that the user can edit. I tried the record current control-set
focus to grid-set focus back to control, but could not get it to work. For
some reason, form.activecontrol would return '' even though the focus was
set to a particular control, and I could not get it to reliably save the
current control. I have not had time to pursue this further to see why
form.activecontrol is empty even though the user is editing a textbox at the
time.

I would use an edit box, but the entries on the