Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
495
Error when using UltraGridExcelExporter in separate thread
posted

Let me explain the situation:

we have a UltraWinGrid placed on a Windows Form. This grid contains one column which has a special column. This column contains a specific control which displays an image.

We added a 'Export to Excel'-button to export the data in the grid to Excel using the UltraWinGrid.ExcelExport.UltraGridExcelExporter-class.

We perform this export in a separate thread because this operation can take a while and we don't want to 'freeze' our main UI-thread.

Now our problem: when we execute the export we get the following error :

Message: Controls created on one thread cannot be parented to a control on a different thread.
Stack Trace:

at System.Windows.Forms.Control.ControlCollection.Add(Control value)
at Infragistics.Win.ControlContainerEditor.GetRendererImage(Size imageSize, EmbeddableEditorOwnerBase owner, Object ownerContext, ControlContainerEmbeddableUIElement controlContainerEmbeddableUIElement)
at Infragistics.Win.UltraWinGrid.GridExportCache.GetControlContainerEditorImage(Size imageSize, UltraGridRow gridRow, UltraGridColumn gridColumn, Object exportValue)
at Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter.WriteValueCell(UltraGridExporterHelper exportHelper, UltraGridRow row, UltraGridColumn ugColumn, Rectangle valueCellRect)

...

When I remove the image-column in the grid or replace it with a classic checkbox-control, it all works well.

So when the grid-data is exported in a separate thread, somehow the control in the main thread is addressed and this error occurs.

So my question: is this a known problem ? Or is there a event we have to capture in our control ?

I already worked with the InvokeRequired()-function in my control-events, but no resolution...

  • 71886
    Offline posted

    Hello timdelma,

    This means that you cannot make calls from a thread which does not host the target control. If you have created the control in Thread1, you will not be able to make calls to it from Thread2 for example. This rule comes from the .NET.

    Please also note that our controls are not thread-safe.