We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Optimization

I''d like to know if there is any way to optimize the drawing of the grid in the following project (last post) http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=31431 The grid isn''t that bad in this particular project, but in the real thing, with the data access it''s even more sluggish.

8 Replies

AD Administrator Syncfusion Team July 18, 2005 07:18 PM UTC

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.


MC Martin Cyr July 18, 2005 08:45 PM UTC

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)?


MC Martin Cyr July 18, 2005 09:30 PM UTC

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?


AD Administrator Syncfusion Team July 18, 2005 10:00 PM UTC

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.


MC Martin Cyr July 19, 2005 12:25 PM UTC

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?


AD Administrator Syncfusion Team July 19, 2005 01:01 PM UTC

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).


MC Martin Cyr July 19, 2005 01:09 PM UTC

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.


MC Martin Cyr July 19, 2005 06:01 PM UTC

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. GridEmbeded-Sample_9426.zip

Loader.
Live Chat Icon For mobile
Up arrow icon