I''d like to know if there is any way to optimize the drawing of the grid in the following project (last post)
The grid isn''t that bad in this particular project, but in the real thing, with the data access it''s even more sluggish.
ADAdministrator Syncfusion Team July 18, 2005 02:18 PM
Putting a UserControl in every cell using GridGenericCellRenderer is costly. Every time a static cell is drawn, the user control is situated off-screen, and a bitmap snapshot is taken, and then this bitmap is then drawn on screen. If you could statically draw what you want to see (couple of rectangles with some text in them) instead of using the base class GridGenericCellRenderer when the cell is not active, I think things would speed up. You could test this out just by calling GridStaticCellRenderer.DrawText instead of calling the baseclass in the static case. This would give you an idea of how much drawing the usercontrol off screen is costing.
MCMartin CyrJuly 18, 2005 03:45 PM
Great idea. Seems to change everything from what I just tested! Do you know of any helper functions to DrawText with style (on two lines, horizontally and vertically centered)?
MCMartin CyrJuly 18, 2005 04:30 PM
Did you mean that I should not use grid in cells?
That I should simply draw two lines in each cell (diving it in 4) and then draw text in each of the corners?
ADAdministrator Syncfusion Team July 18, 2005 05:00 PM
The idea would be to avoid calling the baseclass code to do the drawing for the static path through renderer.Ondraw. You can use the shared method, GridStaticCellRenderer.DrawText method to draw the text. You can call e.Graphics.DrawLine to draw the lines you want to see. Doing it this way is more efficient than using the baseclass call that does the bitmap technique to display an arbitary usercontrol. (If you usercontrol was more involved, then this static drawing might not be an option, but it looks like you just has simple texboxes which should be simple to draw.
You can still use the GridInCell for the active drawing of the cell as there will only be one at most of these cells being used at any one point. All the other cells will be using the static drawing code.
MCMartin CyrJuly 19, 2005 07:25 AM
I think that you''re right. Is there a way to specifiy that the CellType for the active cell is different than the others (is there a BaseStyle for something like that) or should I change it in the OnDraw, or the CellMoving?
ADAdministrator Syncfusion Team July 19, 2005 08:01 AM
I would try handling it in OnDraw. Normally there are 2 paths through this method. One for drawing the active cell, and the other for drawing the non-active cell. So, in your current code, add a method that draws the non-active cell and call this method from OnDraw where you want to draw the nonactive cell, and do not call the baseclass in this case as calling the baseclass will trigger the bitmap technique. (Or you could just put this drawing code directly in OnDraw and avoid the extra method call).
MCMartin CyrJuly 19, 2005 08:09 AM
Ok, but I then keep that code in my CellRenderer class that is based on the GridGenericControlCellRenderer? I tried to do another class based on GridStaticCellRenderer but it never invoke CreateRenderer so I''m confused on what to do with it. I''ll try it in the OnDraw then, thanks.
MCMartin CyrJuly 19, 2005 01:01 PM
Again, thanks a lot Clay, it works just great!
Just in case it''s usefull to anyone, I''ll post the new thing again.
It''s a grid with each cell subdivided in 4. The active cell is an embeded grid. This grid contains usercontrols: one active, and one static repainted as needed. All optimized as much as I could. It''s neat I think now.