I have a virtual grid that only displays static cells. I notice that when I even mouse around other controls on my form (not the grid itself) that QueryCellInfo gets called.
This seems very wastefull. If I am not modifying the style of my grid cells unless the data is either modified or an actual selection is made, then why should I be paying for the cost of querying for the data when a mouse is hovering on the form itself or a neighboring control?
Here is sample that displays the tick count and changes color in any cell when QueryCellInfo is called for that cell. So, it is easy to see when QueryCellInfo is hit.
I put other controls on the form and do not see the behavior you described.
What are you doing differently?
AdministratorMarch 19, 2004 03:46 PM UTC
Hmm, I see what you mean. I''ll take a look at mine again and see what''s going on.
This leads me to ask though, since I don''t plan on changing the cell''s values or styles unless an actual click on a cell or update on the data is performed, is there anyway to prevent the grid from firing QueryCellInfo on plain mouse movements?
I am paying for the cost of getting the data from my models when absolutely nothing is changing on the grid.
AdministratorMarch 19, 2004 03:57 PM UTC
There is really no way for you to control this behavior.
QueryCellInfo tries to cache weak references to styles that are only refreshed when needed. Now, a garbage collection cycle will clear this cache, so any GC would cause QueryCellInfo to fire (the next time the cell is needed for some reason like a mousemove). So, in the sample, even if I move teh nouse over the grid, I dont see teh cells changing. If I start scrolling or clciking then I see values changing.
Now if you do the same work in PrepareViewStyleInfo, there is no cache, an dthat event is fired with every mouse move, etc.
AdministratorMarch 19, 2004 04:29 PM UTC
So in other words there''s no way to really know if QueryCellInfo is being called because the style object was tossed and therefore really needs the data to be set.
Which means many times I may be fetching the data and setting it in the style object when its not really needed? And if I understand there''s no good way around that?
AdministratorMarch 19, 2004 04:59 PM UTC
" may be fetching the data and setting it in the style object when its not really needed?"
No. QueryCellInfo is only fired when something in the grid is requesting the style. If the grid is sitting on the desktop with nothing happening, QueryCellInfo would not be fired. But if you move the mouse over the grid, QueryCellInfo may or may not be fired depending upon whether the requested value is still in the volatile cache. But if you drag another window over the grid so the grid is forced to repaint, then QueryCellInfo will be hit for sure.
If getting the values from your virtual datasource is too time consuming, then you might consider some caching scheme where you efficiently load a cache of data into some quick lookup structure, and use this structure to feed QueryCellInfo.