Background
I am using the UltraDataSource to bind to an UltraGrid in LoadOnDemand mode. The ultradatasource receives updates after it is bound to the grid and the first update is very large so I lock on an object and process the updates.
The hierachy of the data being processed is such that there are up to 15 top level Rows all with their own Bands - which are childbands of UltraDataSource's Band property.
These top level rows have at least one child row each and in some cases these child rows have child rows themselves - which have a different Band.
I add the top level bands at start up - because i know the columns - but there are no rows. When the rows arrive in this initial update i have to add the grand child's band to the row. I do that with this code:
Rows[ParentRowIndex].GetChildRows(ParentRowBandName)[ParentRowIndex].Band.ChildBands.Add("ChildBandName")
The above is an abridged version of my code which has checks for nulls etc.
Once the child band is added i add the child band's columns.
My 2 questions
1. When i add the childband columns i notice the UltraGrid's RowInitializeRow event gets fired, but the data has not been set yet in the datasource. Is there a way i can prevent the row init from firing until the update has finished processing?
2. When adding the columns to the child band the grid loading (which has a lock so get cell data requested handler is blocked until this is complete) takes a lot longer than if columns are added to the bands before binding to the grid.
I know the above because i moved the top level bands's column adding to initialisation of the ultradatasource before binding and it sped it up, problem is i dont know which child rows have grandchildren so i have to add the columns when those grand child rows arrive in an update. i know the above has been covered in other threads - suggestions such as begin / end update and row synching but that has not made much of a difference. Any other ideas are definitely weclome.
FYI - during testing the first update has 15 top level rows each with 36 child rows and then about 10 of those child rows have grand child rows. The top level band has one column, the child band has 71 columns and the grandchild's band has 16 columns.
In addition i am getting the exception below when I give focus to the grid while it appears to be adding the rows and columns to the ultra data source. If i dont move the mouse over the grid or force it to have focus the grid loads without exception. This exception was spotted by someone in 2007 and Mike Saltzman suggested a Hot Fix would address it. I am on verion 9.2 of Infragistics, has anyone else seen this exception and know what causes it or more importantly how to fix it?
System.NullReferenceException: Object reference not set to an instance of an object. at Infragistics.Win.UltraWinGrid.UltraGridBand.ValidateColumnCardFontCache() at Infragistics.Win.UltraWinGrid.UltraGridColumn.VerifyCardLabelSizeCache() at Infragistics.Win.UltraWinGrid.UltraGridColumn.get_CardLabelSize() at Infragistics.Win.UltraWinGrid.UltraGridColumn.get_Width() at Infragistics.Win.UltraWinGrid.UltraGridColumn.get_Extent() at Infragistics.Win.UltraWinGrid.ColumnHeader.get_Extent() at Infragistics.Win.UltraWinGrid.UltraGridBand.CalculateBandMetrics(UltraGridBand priorBand) at Infragistics.Win.UltraWinGrid.BandsCollection.CalculateBandMetrics(Int32 pass) at Infragistics.Win.UltraWinGrid.BandsCollection.CalculateBandMetrics() at Infragistics.Win.UltraWinGrid.ColScrollRegionsCollection.InitializeMetricsHelper() at Infragistics.Win.UltraWinGrid.ColScrollRegionsCollection.InitializeMetrics() at Infragistics.Win.UltraWinGrid.UltraGridLayout.get_BandsOverallExtent() at Infragistics.Win.UltraWinGrid.UltraGridLayout.GetOverallExtent(ColScrollRegion csr) at Infragistics.Win.UltraWinGrid.ColScrollRegion.WillScrollbarBeShown(ScrollbarVisibility assumeRowScrollbarsVisible) at Infragistics.Win.UltraWinGrid.ColScrollRegionsCollection.AreScrollbarsVisible(ScrollbarVisibility assumeColScrollbarsVisible) at Infragistics.Win.UltraWinGrid.RowScrollRegion.IsRowFullyVisible(ScrollbarVisibility colScrollbarVisibility, VisibleRow visibleRow) at Infragistics.Win.UltraWinGrid.RowScrollRegion.IsFirstScrollableRowVisible(ScrollbarVisibility colScrollbarVisibility) at Infragistics.Win.UltraWinGrid.RowScrollRegion.WillScrollbarBeShown(ScrollbarVisibility assumeColScrollbarsVisible) at Infragistics.Win.UltraWinGrid.ScrollRegionBase.WillScrollbarBeShown() at Infragistics.Win.UltraWinGrid.RowScrollRegion.PositionScrollbar(Boolean resetScrollInfo) at Infragistics.Win.UltraWinGrid.ScrollRegionBase.set_ScrollbarRect(Rectangle value) at Infragistics.Win.UltraWinGrid.DataAreaUIElement.AddIntersectionHelper(UIElementsCollection oldElements, RowScrollRegion rsr, ColScrollRegion csr, RowScrollRegion rsrPrevious, ColScrollRegion csrPrevious, Boolean lastVisibleRsr, Boolean lastVisibleCsr) at Infragistics.Win.UltraWinGrid.DataAreaUIElement.PositionChildElements() at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UltraWinGrid.DataAreaUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UltraWinGrid.DataAreaUIElement.set_Rect(Rectangle value) at Infragistics.Win.UltraWinGrid.UltraGridUIElement.PositionChildElements() at Infragistics.Win.UIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UltraWinGrid.UltraGridUIElement.VerifyChildElements(ControlUIElementBase controlElement, Boolean recursive) at Infragistics.Win.UIElement.VerifyChildElements(Boolean recursive) at Infragistics.Win.UltraWinGrid.UltraGridUIElement.InternalInitializeRect(Boolean verify) at Infragistics.Win.UltraWinGrid.UltraGridLayout.GetUIElement(Boolean verify, Boolean forceInitializeRect) at Infragistics.Win.UltraWinGrid.UltraGrid.OnPaint(PaintEventArgs pe) at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs) at System.Windows.Forms.Control.WmPaint(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Hello,
Would you be able to provide a sample project which reproduces the issue? You can attach a file to a post by clicking the Options tab while editing the post.
I ran your sample and it seemed to run fine. Could you tell me exactly what I need to do to reproduce the issue?
Without changing anything (no uncommenting of marshalling code to the UI thread) you just run it and you should get an exception.
Couple of questions:
1. What version of Infragistics did you use?
2. Did you leave the line "ultraGrid1.Invoke((Action)delegate {" in of "PopulateDataSource" in Form1 commented out so the update is performed on the Background thread rather than being marshalled to the UI thread?
Hi,
I tried your sample with NetAdvantage 10.1 (latest SR) and I did not get an exception, either. But I can tell you with certainty that what you are doing here is not going to work. I'm not at all surprised that you are getting exceptions with this code.
Neither the WinGrid, nor the DataSet class, nor the BindingManager in DotNet are thread-safe. So binding a control to a DataSet and then modifying that DataSet on a separate thread is almost certain to cause a race condition and there is no way you can effectively handle that because you are not in control of the communication between any of those objects.
There is a long, detailed discussion about this here:
Work with a dataset bound to a grid on a separate thread - Infragistics Community
Very interesting that both of you got the sample project to work on 10.1 but as you state and your attached thread reiterates, the Binding Manager is not threadsafe. As such i will persevere on the UI thread.
Thanks for your help Dave and Mike.
grasshopper said:Very interesting that both of you got the sample project to work on 10.1
This is really not all that surprising. One of the hallmarks of threading issues is that they are inconsistent. My guess is that we would eventually experience an exception in some completely unrelated and baffling place in the code that has nothing specifically to do with threading. These kinds of errors often occur when the grid tries to paint itself and finds that something has gotten out of synch, but there's no indication why.