Andrew Price
2025-03-17T08:28:53Z
Hi

Experiencing very slow Excel access when using CustomDrawCellBackground.

I have a grid which list reports available in my application for the user to select and run.
There are 76 rows with 20 columns (one image, two text and 17 check boxes).

I wrote Display, Print, CSV, PDF and Excel export routines for the reports (all working fast).

One large report exports to excel in 10 seconds.

I then added a CustomDrawCellBackground event to draw a progress bar and % text in a cell for the row of the report being exported.
Takes about 15 seconds now to export to excel.

As I did not like the standard checkboxes (mostly because of the background colour which I could not fine a way to change), I used the CustomDrawCellBackground to draw all checkboxes in the grid (nice pale green background).

The same export to excel now takes several minutes.

I noticed that every call to Excel causes the CustomDrawCellBackground event to be raised for each cell several times (I don't know why).
I use Excel.Range to apply an excel style to ranges of cells so that I can duplicate the formatting of the grid content. e.g. font, colours, number formatting etc.

I then removed the code for drawing the textboxes within CustomDrawCellBackground, and created a CustomButtonRenderer class attaching this to iGrid.CustomControlPaint. This gave the grid the same look as previously, but it still caused the export to take a long time.

The only way I can get the speed, and keep my checkboxes, is to call "SendMessage(iGrid.Handle, WM_SETREDRAW, True, IntPtr.Zero)" to suspend iGrid drawing and then again (with false) to re-enable the drawing), before and after my excel.range calls.
However, using this approach prevents my progress bar from being displayed within the grid.
Using BeginUpdate and EndUpdate does not change the speed.

Help?
Igor/10Tec
2025-03-19T16:01:56Z
We do not know how you export iGrid to Excel. If you send us a sample demonstrating the issue, we can investigate this performance problem and perhaps find a way how to speed it up.
Andrew Price
2025-03-20T09:04:25Z
I created a simple demo project last night to help recreate this issue, and noticed (by placing a counter in the CustomDrawCellBackground event and updating a label on the form with the counter) that this was called whenever the mouse moved over a checkbox, or the grid was scrolled. This is what I expected.

Doing the same in my application displayed a constantly updated counter, even when no activity in the grid.

On stepping through my main project, I noticed that the CellDynamicContents event was being constantly raised and in this I update the cell content of each row to indicate if the report is available to run. This update was then triggering the CustomDrawCellBackground event. When previously pausing my main project it would always stop in CustomDrawCellBackground whenever a call to excel.range was made, making me think this was the main culprit.
So it appears the issue was with me using the CellDynamicContents event. I do not know why this is being raised so often, but I can move the code within it which will remove my speed problem allowing me to still update a progress bar within CustomDrawCellBackground.

Sorry for any alarm I may have caused.


Igor/10Tec
2025-03-20T14:43:40Z
CellDynamicContents is raised by iGrid only while drawing cells in the viewport - when iGrid needs to know cell text and image. You should not update anything in iGrid in an event handler of this event because this can cause repainting and subsequent CellDynamicContents events, which can lead to an endless loop.
Andrew Price
2025-03-21T05:08:21Z
Yes I believe that is what caused my problem - oops!