Discussion:
grid refreshing
(too old to reply)
Ross Wyborn
2008-12-01 19:50:15 UTC
Permalink
Is there a way to refresh a grid without painting the current row as the
first row in the grid?

My application has a table in a grid with a bunch of numbers. I want to add
the rows and columns as the numbers are entered just like an excel
spreadsheet.
I attached the addition procedure to the onSelChange of the grid. To prevent
the cursor changing in the grid I saved the row then opened a new query to
make the additions (looped through the new query) Totals of the
columns(fields) go into entryfields on the form and this is fine. The totals
of the row goes into a total field in the rowset. I refresh the rowset, then
refreshcontrols then refresh the grid. It all works well except I find it
annoying that the enteries that have been made scroll off screen. If I leave
out the grid refresh the field will not refresh until the user clicks on
that field (somethink the user should not do). If I put in a rowset.first it
goes into an endless loop and crashes the program. I don't want it to go to
the first row anyway.

Any advice would be appreciated.

Ross Wyborn
Greg Hill
2008-12-01 21:25:01 UTC
Permalink
Post by Ross Wyborn
Is there a way to refresh a grid without painting the current row as the
first row in the grid?
Yes,
Before you make edits or just simply refresh get 2 bookmarks

form.bookMark = form.grid1.datalink.bookMark() // if you make a change in
the index this will be lost.
form.gridBookMark = form.grid1.firstRow()

do your edting or refresh the grid and such.

Then do the following:

form.grid1.datalink.goto(form.gridBookMark)
form.grid1.datalink.goto(form.bookMark)

if not form.grid1.firstRow() = bM
do
form.grid1.datalink.next()
if form.grid1.datalink.endOfSet
exit
endif
until form.grid1.datalink.bookMark() = bM
endif

NOTE: You might be able to throw out the rowset.refresh() because moving
the record point as seen above (depending on your application) will refresh
the row.

I hope this make sense<g>

Greg Hill
Post by Ross Wyborn
My application has a table in a grid with a bunch of numbers. I want to
add the rows and columns as the numbers are entered just like an excel
spreadsheet.
I attached the addition procedure to the onSelChange of the grid. To
prevent the cursor changing in the grid I saved the row then opened a new
query to make the additions (looped through the new query) Totals of the
columns(fields) go into entryfields on the form and this is fine. The
totals of the row goes into a total field in the rowset. I refresh the
rowset, then refreshcontrols then refresh the grid. It all works well
except I find it annoying that the enteries that have been made scroll off
screen. If I leave out the grid refresh the field will not refresh until
the user clicks on that field (somethink the user should not do). If I put
in a rowset.first it goes into an endless loop and crashes the program. I
don't want it to go to the first row anyway.
Any advice would be appreciated.
Ross Wyborn
Ross Wyborn
2008-12-02 00:43:46 UTC
Permalink
Hi Greg,
The problem is not with the pointer in the grid. The pointer is in the
correct location. This is because I have used a seperate query to add up
the numbers. The problem is that the grid refresh repaints the grid with the
current row on top. dBase help says that it does that. The problem it that
records above this are off the grid.
There are not many records in the table (10-20) as I am using temporary
tables to make it multi-user.

Thaks for the input.

Ross Wyborn
Post by Greg Hill
Post by Ross Wyborn
Is there a way to refresh a grid without painting the current row as the
first row in the grid?
Yes,
Before you make edits or just simply refresh get 2 bookmarks
form.bookMark = form.grid1.datalink.bookMark() // if you make a change in
the index this will be lost.
form.gridBookMark = form.grid1.firstRow()
do your edting or refresh the grid and such.
form.grid1.datalink.goto(form.gridBookMark)
form.grid1.datalink.goto(form.bookMark)
if not form.grid1.firstRow() = bM
do
form.grid1.datalink.next()
if form.grid1.datalink.endOfSet
exit
endif
until form.grid1.datalink.bookMark() = bM
endif
NOTE: You might be able to throw out the rowset.refresh() because moving
the record point as seen above (depending on your application) will
refresh the row.
I hope this make sense<g>
Greg Hill
Post by Ross Wyborn
My application has a table in a grid with a bunch of numbers. I want to
add the rows and columns as the numbers are entered just like an excel
spreadsheet.
I attached the addition procedure to the onSelChange of the grid. To
prevent the cursor changing in the grid I saved the row then opened a new
query to make the additions (looped through the new query) Totals of the
columns(fields) go into entryfields on the form and this is fine. The
totals of the row goes into a total field in the rowset. I refresh the
rowset, then refreshcontrols then refresh the grid. It all works well
except I find it annoying that the enteries that have been made scroll
off screen. If I leave out the grid refresh the field will not refresh
until the user clicks on that field (somethink the user should not do).
If I put in a rowset.first it goes into an endless loop and crashes the
program. I don't want it to go to the first row anyway.
Any advice would be appreciated.
Ross Wyborn
Greg Hill
2008-12-02 01:02:57 UTC
Permalink
NOTE: In my code example there are 2 types of bookmarks one is the
"FIRSTROW" for the grid and the other is the actual row that was selected.
The reason both types of bookMarks are needed is as follows:

Lets say the user selects the 3rd row down from the top in the grid. Then
the routine you have disrupts that position and disprupts the pointer.
Right?
So now you have 2 things to accomplish,
1) Displaying the same rows that were displayed starting from the first row
to the last.
2) Putting the highlight bar on the 3rd row down

The code I posted will do just that.

What I posted doesn't select the top row "UNLESS" that is where the original
row was when you select it.

I had the same problem and resolved it with the method I posted.

Greg Hill
Post by Ross Wyborn
Hi Greg,
The problem is not with the pointer in the grid. The pointer is in the
correct location. This is because I have used a seperate query to add up
the numbers. The problem is that the grid refresh repaints the grid with
the current row on top. dBase help says that it does that. The problem it
that records above this are off the grid.
There are not many records in the table (10-20) as I am using temporary
tables to make it multi-user.
Thaks for the input.
Ross Wyborn
Post by Greg Hill
Post by Ross Wyborn
Is there a way to refresh a grid without painting the current row as the
first row in the grid?
Yes,
Before you make edits or just simply refresh get 2 bookmarks
form.bookMark = form.grid1.datalink.bookMark() // if you make a change in
the index this will be lost.
form.gridBookMark = form.grid1.firstRow()
do your edting or refresh the grid and such.
form.grid1.datalink.goto(form.gridBookMark)
form.grid1.datalink.goto(form.bookMark)
if not form.grid1.firstRow() = bM
do
form.grid1.datalink.next()
if form.grid1.datalink.endOfSet
exit
endif
until form.grid1.datalink.bookMark() = bM
endif
NOTE: You might be able to throw out the rowset.refresh() because
moving the record point as seen above (depending on your application)
will refresh the row.
I hope this make sense<g>
Greg Hill
Post by Ross Wyborn
My application has a table in a grid with a bunch of numbers. I want to
add the rows and columns as the numbers are entered just like an excel
spreadsheet.
I attached the addition procedure to the onSelChange of the grid. To
prevent the cursor changing in the grid I saved the row then opened a
new query to make the additions (looped through the new query) Totals of
the columns(fields) go into entryfields on the form and this is fine.
The totals of the row goes into a total field in the rowset. I refresh
the rowset, then refreshcontrols then refresh the grid. It all works
well except I find it annoying that the enteries that have been made
scroll off screen. If I leave out the grid refresh the field will not
refresh until the user clicks on that field (somethink the user should
not do). If I put in a rowset.first it goes into an endless loop and
crashes the program. I don't want it to go to the first row anyway.
Any advice would be appreciated.
Ross Wyborn
Omar Mohammed
2008-12-01 21:04:47 UTC
Permalink
Post by Ross Wyborn
Is there a way to refresh a grid without painting the current row as the
first row in the grid?
My application has a table in a grid with a bunch of numbers. I want to add
the rows and columns as the numbers are entered just like an excel
spreadsheet.
I attached the addition procedure to the onSelChange of the grid. To prevent
the cursor changing in the grid I saved the row then opened a new query to
make the additions (looped through the new query) Totals of the
columns(fields) go into entryfields on the form and this is fine. The totals
of the row goes into a total field in the rowset. I refresh the rowset, then
refreshcontrols then refresh the grid. It all works well except I find it
annoying that the enteries that have been made scroll off screen. If I leave
out the grid refresh the field will not refresh until the user clicks on
that field (somethink the user should not do). If I put in a rowset.first it
goes into an endless loop and crashes the program. I don't want it to go to
the first row anyway.
Any advice would be appreciated.
Ross Wyborn
Ross
I'm not sure if I understand the situation here but:
Shouldn't you go rowset.last() to go to the newly entered record?
At any rate, grids are a bit of a pain to deal with.
Why don't you add another field in the record. Call it record number.
Then just jump straight to that number? So if the last record was 100
you store it in a variable then after entering a new record, the new
variable and record number is 101, find record 101 and you are at the
currently entered position.
Another thing, I'm not sure how many records we're talking bout but
looping through a grid can slow down your app (maybe that's why it
crashes). Do they need to see all the other entered items or just what
they are dealing with?
HTH
Ross Wyborn
2008-12-02 00:36:38 UTC
Permalink
Hi Omar,
Thanks for replying. The problem is not with the fact that it is not at the
correct position. Because I have used a new query seperate from the rowset
in the grid to do the additions, the pointer says at the correct location.
The problem is that when you do a grid refresh it pastes the current
location at the top of the grid. The correct record does show but records
above this are off the grid. dBase help says that this is what is done with
a grid refresh.
There are not many records in the grid. I am using a temporary table so that
the application can be used by multiple users at the same time. Typically
there will only be about 10-20 records in the table.

Thanks for your input.

Ross Wyborn
Post by Omar Mohammed
Post by Ross Wyborn
Is there a way to refresh a grid without painting the current row as the
first row in the grid?
My application has a table in a grid with a bunch of numbers. I want to
add the rows and columns as the numbers are entered just like an excel
spreadsheet.
I attached the addition procedure to the onSelChange of the grid. To
prevent the cursor changing in the grid I saved the row then opened a new
query to make the additions (looped through the new query) Totals of the
columns(fields) go into entryfields on the form and this is fine. The
totals of the row goes into a total field in the rowset. I refresh the
rowset, then refreshcontrols then refresh the grid. It all works well
except I find it annoying that the enteries that have been made scroll
off screen. If I leave out the grid refresh the field will not refresh
until the user clicks on that field (somethink the user should not do).
If I put in a rowset.first it goes into an endless loop and crashes the
program. I don't want it to go to the first row anyway.
Any advice would be appreciated.
Ross Wyborn
Ross
Shouldn't you go rowset.last() to go to the newly entered record?
At any rate, grids are a bit of a pain to deal with.
Why don't you add another field in the record. Call it record number. Then
just jump straight to that number? So if the last record was 100 you store
it in a variable then after entering a new record, the new variable and
record number is 101, find record 101 and you are at the currently entered
position.
Another thing, I'm not sure how many records we're talking bout but
looping through a grid can slow down your app (maybe that's why it
crashes). Do they need to see all the other entered items or just what
they are dealing with?
HTH
Ross Wyborn
2008-12-04 01:45:42 UTC
Permalink
Hi All,
I finally solved the problem. The problem with using the onSelChange
event of the form is that it fires when you do any bookmarking or locating.
This puts it into an endless loop. If you make the onSelChange = null while
you do the work it does work but navigating puts it back at the first row so
you cannot select the second row because the onSelChange changes it back to
the first row.

How I got around the problem was to use the field onChange event instead of
the grid onSelChange. This way I could navigate back to the first row after
making a change. Of course I had to add the procedure to each field I wanted
to add. Also I had to replace form in the procedure with
this.parent.parent.parent.parent.
Anyway it works fine now and I learnt some lessons.

Thanks for your help.

Ross Wyborn
Post by Ross Wyborn
Is there a way to refresh a grid without painting the current row as the
first row in the grid?
My application has a table in a grid with a bunch of numbers. I want to
add the rows and columns as the numbers are entered just like an excel
spreadsheet.
I attached the addition procedure to the onSelChange of the grid. To
prevent the cursor changing in the grid I saved the row then opened a new
query to make the additions (looped through the new query) Totals of the
columns(fields) go into entryfields on the form and this is fine. The
totals of the row goes into a total field in the rowset. I refresh the
rowset, then refreshcontrols then refresh the grid. It all works well
except I find it annoying that the enteries that have been made scroll off
screen. If I leave out the grid refresh the field will not refresh until
the user clicks on that field (somethink the user should not do). If I put
in a rowset.first it goes into an endless loop and crashes the program. I
don't want it to go to the first row anyway.
Any advice would be appreciated.
Ross Wyborn
Greg Hill
2008-12-04 17:16:30 UTC
Permalink
Post by Ross Wyborn
Hi All,
I finally solved the problem. The problem with using the onSelChange
event of the form is that it fires when you do any bookmarking or
locating. This puts it into an endless loop. If you make the onSelChange =
null while you do the work it does work but navigating puts it back at the
first row so you cannot select the second row because the onSelChange
changes it back to the first row.
How I got around the problem was to use the field onChange event instead
of the grid onSelChange. This way I could navigate back to the first row
after making a change. Of course I had to add the procedure to each field
I wanted to add. Also I had to replace form in the procedure with
this.parent.parent.parent.parent.
Anyway it works fine now and I learnt some lessons.
Thanks for your help.
Good idea!

Glad you got it.

Greg Hill

Loading...