I have an ultra grid which is bound to a binding list. Sometimes, when the data is populated and the grid is bound to the binding list, it throws this exception:
Type : System.ArgumentException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089Message : An item with the same key has already been added.Source : mscorlibHelp link : ParamName : Data : System.Collections.ListDictionaryInternalTargetSite : Void ThrowArgumentException(System.ExceptionResource)Stack Trace : at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at Infragistics.Win.UltraWinGrid.UltraGridRow.get_ScrollCountInternal() at Infragistics.Win.UltraWinGrid.UltraGridRow.Infragistics.Shared.ISparseArrayMultiItem.get_ScrollCount() at Infragistics.Shared.SparseArray.GetItemAtVisibleIndex(Int32 visibleIndex, ICreateItemCallback createItemCallback) at Infragistics.Shared.SparseArray.GetItemAtVisibleIndexOffset(ISparseArrayMultiItem startItem, Int32 offset, ICreateItemCallback createItemCallback) at Infragistics.Win.UltraWinGrid.ScrollCountManagerSparseArray.GetItemAtVisibleIndexOffset(UltraGridRow startRow, Int32 offset) at Infragistics.Win.UltraWinGrid.RowsCollection.GetRowAtVisibleIndexOffset(UltraGridRow startAtRow, Int32 visibleIndexOffset, IncludeRowTypes includeRowTypes) at Infragistics.Win.UltraWinGrid.RowsCollection.GetNextVisibleRow(UltraGridRow row, IncludeRowTypes includeRowTypes) at Infragistics.Win.UltraWinGrid.RowsCollection.GetNextVisibleRow(UltraGridRow row) at Infragistics.Win.UltraWinGrid.ViewStyleBase.AddSiblingRows(VisibleRowFetchRowContext& context, VisibleRow parentVisibleRow, UltraGridRow firstSibling) at Infragistics.Win.UltraWinGrid.ViewStyleBase.RecreateRowList(RowScrollRegion rsr) at Infragistics.Win.UltraWinGrid.RowScrollRegion.RegenerateVisibleRows(Boolean resetScrollInfo) at Infragistics.Win.UltraWinGrid.RowScrollRegion.WillScrollbarBeShown(ScrollbarVisibility assumeColScrollbarsVisible) at Infragistics.Win.UltraWinGrid.RowScrollRegionsCollection.AreScrollbarsVisible(ScrollbarVisibility assumeColScrollbarsVisible) at Infragistics.Win.UltraWinGrid.ColScrollRegion.ResetScrollInfo() at Infragistics.Win.UltraWinGrid.ScrollRegionBase.ShowScrollbar(Boolean show, Boolean resetScrollInfo) at Infragistics.Win.UltraWinGrid.ColScrollRegion.PositionScrollbar(Boolean resetScrollInfo) at Infragistics.Win.UltraWinGrid.ColScrollRegion.RegenerateVisibleHeaders() at Infragistics.Win.UltraWinGrid.ColScrollRegionsCollection.InitializeMetricsHelper() at Infragistics.Win.UltraWinGrid.ColScrollRegionsCollection.InitializeMetrics() at Infragistics.Win.UltraWinGrid.RowScrollRegion.RegenerateVisibleRows(Boolean resetScrollInfo) at Infragistics.Win.UltraWinGrid.RowScrollRegion.WillScrollbarBeShown(ScrollbarVisibility assumeColScrollbarsVisible) at Infragistics.Win.UltraWinGrid.RowScrollRegionsCollection.AreScrollbarsVisible(ScrollbarVisibility assumeColScrollbarsVisible) at Infragistics.Win.UltraWinGrid.ColScrollRegion.WillScrollbarBeShown(ScrollbarVisibility assumeRowScrollbarsVisible) at Infragistics.Win.UltraWinGrid.ColScrollRegion.PositionScrollbar(Boolean resetScrollInfo) at Infragistics.Win.UltraWinGrid.ScrollRegionBase.SetOriginAndExtent(Int32 origin, Int32 extent) at Infragistics.Win.UltraWinGrid.ColScrollRegion.SetOriginAndExtent(Int32 origin, Int32 extent) at Infragistics.Win.UltraWinGrid.DataAreaUIElement.ResizeColScrollRegions() 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.DrawHelper(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Boolean clipText, Boolean forceDrawAsFocused, Boolean preventAlphaBlendGraphics) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode, Size elementSize, Boolean preventAlphaBlendGraphics) at Infragistics.Win.ControlUIElementBase.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode) at Infragistics.Win.UltraWinGrid.UltraGridUIElement.Draw(Graphics graphics, Rectangle invalidRectangle, Boolean doubleBuffer, AlphaBlendMode alphaBlendMode) at Infragistics.Win.UltraControlBase.OnPaint(PaintEventArgs pe) 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)
A big Red cross mark is shown in the grid and no data is populated. This is not happening every time and is not consistent with any flow. Please check what could be the possible reason for this and let me know in case you need more info.
What version of the grid are you using?
Is your application using multiple threads? This error could easily be caused by a threading issue. It also might be a bug that is already fixed.
So my first recommendation would be to get the latest service release if you don't already have it.
How to get the latest service release - Infragistics Community
I am using NetAdvantage Ultimate v 10.3.20103.1000. Regarding multiple threads, the data is retrieved in a background thread and on the completion of the background thread it is assigned to the grid using a binding list.
Is the grid bound to the data source before you start your background thread?
If not, and you are absolutely certain that the entire DataSource has been marshalled to the UI thread before you assign the grid's DataSource, then that would not cause a problem.
But since you are having a problem that I have seen occur with improper use of threads, my guess is that one of two things is going on:
Or, of course, this could be the bug I referred to in my previous post. In which case, the solution is to get the latest service release.
Hi Adeel,
There's not much information here to go on in terms of what you are actually doing. But there are really very few things you can do that mix mutli-threading and databinding together safely.
Whenever you use threads, you have to marshal any information across those threads, and this is typically impossible when you are using DataBinding, because you are not in control of the communication between the grid, the BindingManager, and the data source.
I don't know exactly what you mean by "using thread to rebind data", but I cannot imagine any possible meaning of that phrase that could possible work safely.
I am facing the same issue Mike,
my scenario is almost the same as i am using thread to rebind data.and if i do my functionality in one thread (the thread in which application is running) Application runs fine...but i want to do it in seperate thread....can i do it or not....if yes then what are the possible solutions.
Hi,
The fact that it does not occur consistently is a strong indication that it is a threading issue. That's one of the hallmarks of threading problems. The exception occurs long after the actual problem has occurred.
You have to be extremely careful when you try to use threading and databinding together, because you have no control over the communication between the BindingManager, the DataSource, and the bound control(s) and therefore you cannot properly marshal any of the communication.
I also suspected it to be a threading issue, but as it does not occur consistently I thought it could be something else. I will dig dipper into it and see if it is happening because of one of the reasons mentioned by you.