Hi.
I am using an UltraWinGrid (v 8.2). I am binding a custom object to the grid. I have a method that loops through the rows in the grid, checks the IsExpandable property of each row and does some processing based on it. Sporadically, I get the following error message while checking the IsExpandable property. I have set in bold the part of the stack trace that is relevant after the IsExpandable property is accessed.
Even when the error happens multiple times in sucession, its on different rows.
I would appreciate any help. Thanks.
System
.NullReferenceException: Object reference not set to an instance of an object. at Infragistics.Win.UltraWinGrid.UltraGridRow.HasChild(UltraGridBand band, Boolean excludeHidden, IncludeRowTypes includeRowTypes) at Infragistics.Win.UltraWinGrid.UltraGridRow.get_IsExpandable() at Utility.GridUtility.GridUtility.AddRowsForXLRaw(RowsCollection rows, Int32& index, PortfolioHeading headings, Worksheet ws, String& ls, XLRawSettings settings) in C:\Karsch\tag\Release 5.0.4.0\MiddleWare\Messaging\Utility\GridUtility\GridUtility.cs:line 1807 at .........
Myabe one of your parameters is null? Can you debug and check this?
Hi Amiram,
Thank you for your response. I had been away for a while and just returned. I tried your solution, but it did not work. Now I get a NullReferenceException on the Invoke statement. The stack trace is below.
.NullReferenceException: Object reference not set to an instance of an object. at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous) at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args) at Utility.GridUtility.GridUtility.AddRowsForXLRaw(RowsCollection rows, Int32& index, PortfolioHeading headings, Worksheet ws, String& ls, XLRawSettings settings) in C:\Karsch\tag\Release 5.0.5.0\MiddleWare\Messaging\Utility\GridUtility\GridUtility.cs:line 1620 at Utility.GridUtility.GridUtility.ExportRawDataToExcel(UltraGrid grid, IGridDataBroker broker, XLRawSettings settings) in C:\Karsch\tag\Release 5.0.5.0\MiddleWare\Messaging\Utility\GridUtility\GridUtility.cs:line 1435
Thanks,
Maha
Multithreading is the problem, and the fact that this problem occurs sporadically fits in.
There is no way to access a GUI component from a thread other than the GUI component thread, unless you use invocation.
The fix to your method goes like that:
1. Create a delegate with the same signature as your method. (Usually you can use Action or Func but I don't think you can find a long overload like that).
2. Add this code in you method:
private static void AddRowsForXLRaw(RowsCollection rows, ref int index,PortfolioHeading headings, Worksheet ws, ref string ls, XLRawSettingssettings)
{
if (Rows.Band.Layout.Grid.InvokeRequired)
Rows.Band.Layout.Grid.Invoke(new yourDelegate(AddRowsForXLRaw), rows, ref index, headings, ws, ref ls, settings)
}
else
// the rest of you code
Yes. I use multi-threading. Basically, if a user requests a excel report based on the grid data, I launch a new thread to generate the report. The grid could have upto 3 bands. The report generation function loops through the rows one at a time and adds it to the report. If a row has child rows, it recursively loops though each of the child rows.
The error occurs sporadically when the I check the IsExpandable property of each row (please see the words highlighted in red below).
private static void AddRowsForXLRaw(RowsCollection rows, ref int index, PortfolioHeading headings, Worksheet ws, ref string ls, XLRawSettings settings)
foreach (UltraGridRow row in rows)
if ((row.IsGroupByRow || row.IsExpandable) && !
settings.RemoveGroupings)
foreach (UltraGridChildBand band in row.ChildBands)
AddRowsForXLRaw(band.Rows, ref index,
headings, ws, ref ls, settings);
// Processing for report generation
I have also tried to wrap accessing the IsExpandable property in a try-catch block and then wait for a specified time before attempting to process the same row again. The issue does not go away even after waiting for a minute. However, if I launch the report again even after a few secs, the report geenrates sometimes. Even if the error occurs again, its on a different row. I am not sure why the error in a particular row goes away when the report is regenerated, but does not when I make the thread sleep for 1 minute.
While I do not have a lock for synchronization, I have seen this happen even when there is nothing else modifying the grid.
Please let me know if I can provide any additional information.
Do you use Multithreading?
Can you put some code?