Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Speeding up the grid
Message
From
16/10/2001 05:23:43
 
 
To
15/10/2001 11:06:46
Jimi Lee
Pop Electronic Products Ltd.
Hong Kong, Hong Kong
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00568452
Message ID:
00568901
Views:
13
Hi!

It is messy and most likely will be hard for you to workaround, specially with filters. I did not implemented it, but I investigated this question and workaround is complex. Better do not try to implement it if you have no time for that or it is too complex.

First of all, you need to catch the mouse coordinates over the grid. You can only use mrow() and mcol() functions in the BeforeRowColChange event of the grid. This is because MouseDown event of the control is fired AFTER grid refreshed lines. You need to update correct record number before this happens. To do this, you require to determine what row is clicked BEFORE refrshing, that you can do only in the BeforeRowColChange event. Using mouse coordinates you can use the GridHitTest function to determine where mouse clicked. This way you see if it is clicked in the same row (so no need to refresh) or in another row. When in another row, you need to use current Relative row value of grid and relative row returned by GridHitTest to determine how much records you need skip back or forward to change record pointer. When scanning foward - you will need special actions like grid refreshing. Whan scanning back - you're lucky. This is because when you move record pointer in grid, two lines are refreshed from top to bottom. When new position is above current line, you will know new line very quickly. When new position is below, you will not know it for sure.

To highlight row, use function like following (here it is a method of grid called from DynamicBackColor expression):
* grid.DoHighlight
lparameters nColumn
if this.lGoingChange
	this.lGoingChange = .F.
	this.nRecNo=recno(this.RecordSource)
endif
return iif(this.nRecNo=recno(this.RecordSource), gnGridHighlightingColor,nColumn.BackColor)
gnGridHighlightingColor - color of highlighting.
lGoingChange - flag set by BeforeRowColChange to notify this method that row is going to change from the current row to the row ABOVE current.
nRecNo - property that stores current row to track which row to highlight.

One more problem - you need to handle situation when grid is scrolled so current row is not visible. In such case RelativeRow property of grid returns 0 and you cannot use it. You will require to track if current row is above or below the visible area in the Scrolled event of the grid.

Unfortunately, for row below the current you will require to do a skip to determine correct record number, specially when you use filters. In addition, when grid is scrolled by way that current row is not visible, you will not be able to determine how many records you need to skip to determine a record number of new row. In addition, skipping some number of records in filtered recordset is the same as just refreshing a grid completely.

When user navigates a column with Sparse=.F., all rows between current and new row are refreshed. Better just refresh entire grid in such case, though you can try to play more with these things and see if you can avoid that too, but this is depended on many column settings.

You can easy track all mentioned above events by putting DebugOut command with some text in the DoHighlight method - in output window you will see how grid refresh its rows, in which order and what you can do to make it better.

HTH.

>Hi Vlad,
>
>Yeah, would you please tell me the way to change the backcolor of rows without refreshing the whole grid? I'd like to learn about it.
>
>About my program, I have two tables, TableOne as the main table and TableTwo with relations to TableOne..
>
>My grid has 12 columns, first 7 showing data from TableOne, but not the first 7 fields. 8-9 showing data from TableTwo, 10-12 also showing data from TableOne, but is using iif(,,) to select the correct value.
>
>Then, I use set filter to type=="xx" to show the records I want.
>
>And in the afterrowcolchange, i have:
>
>LPARAMETERS nColIndex
>nGridRecNo = this.activeRow
>this.SetAll('DynamicBackColor', "iif(nGridRecNo==this.activerow,";
>     +allt(str(RGB(0,200,200)))+ "," + allt(str(this.BackColor));
>     + ")",'Column')
>this.refresh
>
>
>There also some more codes but I think it doesn't matter.. such as
>set cursor on in when event, set cursor off in valid event..
>
>without the code in afterrowcolchange, the speed is quite ok, but with the code, the refresh rate is very poor.. what do you think?
>
>Jimi
>
>>Hi!
>>
>>Yes, there is a way to refresh the back color of the line without call of the Grid.Refresh, but the approach is somewhat complex and is not tested in the live environment in production. If you want, I can describe it, but it has also disadvantage - while speed of rows refreshing is better when you navigate them, as soon as the entire grid is refreshed, it bocemes slightly slower than with usuall approach. This is because you will need to use custom method call from DynamicBackColor expression instead of using iif() function. The slow down is little, however, compare to how it could be slow when refreshing the entire grid with filtered recordset.
>>
>>You're right, it is better to use views instead of filtered table.
>>
>>If you want, I can look to your code and tell you which parts cause slow down and how to change them to speed up the forms.
>>
>>
>>>hi all,
>>>
>>>filtering the table on a grid would slower the process, switching to views instead of tables makes it better. But then, I have to put a dynamicbackcolor on the afterrowcolchange event to give the users a "listbox feel".
>>>
>>>This makes the program very slow, the refresh rate is very significant. Is it possible to change the backcolor of 2 rows (jumping from 1 row to another), without refreshing the whole grid? Or are there any other way to set the color in a faster way?
>>>
>>>sigh, always have speeding problems in my program :-\
>>>
>>>Thanks in advance!
>>>Jimi
Vlad Grynchyshyn, Project Manager, MCP
vgryn@yahoo.com
ICQ #10709245
The professional level of programmer could be determined by level of stupidity of his/her bugs

It is not appropriate to say that question is "foolish". There could be only foolish answers. Everybody passed period of time when knows nothing about something.
Previous
Reply
Map
View

Click here to load this message in the networking platform