I am getting an ArgumentException throw when I switch datasources. I am using a BindingList on an internal business object and when I try to switch the initial binding list for an alternative instance of the same class I get an ArgumentException ("Key Already exists").
I have tried resetting the DisplayLayout viz,
grid.DataSource = null;
grid.DisplayLayout.Reset();
grid.DataSource = newBindingList;
But I still get the exception.
The stack trace from the exception is:
. at Infragistics.Shared.KeyedSubObjectsCollectionBase.ValidateKeyDoesNotExist(String key, IKeyedSubObject ignoreObject) at Infragistics.Shared.KeyedSubObjectsCollectionBase.ValidateKey(String key, IKeyedSubObject ignoreObject) at Infragistics.Shared.KeyedSubObjectsCollectionBase.ValidateKey(String key) at Infragistics.Shared.KeyedSubObjectsCollectionBase.InternalAdd(IKeyedSubObject obj) at Infragistics.Win.UltraWinGrid.ColumnsCollection.InternalAdd(UltraGridColumn column) at Infragistics.Win.UltraWinGrid.UltraGridBand.InitColumns(UltraGridBand[ oldBands) at Infragistics.Win.UltraWinGrid.UltraGridBand.InitListManager(BindingManagerBase bindingManager, String dataMember, UltraGridBand[ oldBands) at Infragistics.Win.UltraWinGrid.UltraGridLayout.ListManagerUpdated(BindingManagerBase bindingManager) at Infragistics.Win.UltraWinGrid.UltraGridLayout.ListManagerUpdated() at Infragistics.Win.UltraWinGrid.UltraGridBase.Set_ListManager(Object newDataSource, String newDataMember) at Infragistics.Win.UltraWinGrid.UltraGridBase.set_DataSource(Object value) at AspenTech.AspenCxs.InfragisticsControls.CxsExplorer.SynchronizeDetailsView(CxsNodeCollection newNodes) in C:\Rnd\AspenCXS\dev\Source\AspenTech.AspenCxs.InfragisticsControls\CxsExplorer.cs:line 174 at AspenTech.AspenCxs.InfragisticsControls.CxsExplorer._treeNavigator_AfterSelect(Object sender, SelectEventArgs e) in C:\Rnd\AspenCXS\dev\Source\AspenTech.AspenCxs.InfragisticsControls\CxsExplorer.cs:line 146 at Infragistics.Win.UltraWinTree.UltraTree.OnAfterSelect(SelectEventArgs e) at Infragistics.Win.UltraWinTree.UltraTree.FireEvent(TreeEventIds id, EventArgs e) at Infragistics.Win.UltraWinTree.UltraTree.SelectNewSelection(SelectedNodesCollection selected, Boolean isRangeSelect) at Infragistics.Win.UltraWinTree.UltraTree.SelectNewSelection(SelectedNodesCollection selected) at Infragistics.Win.UltraWinTree.UltraTree.InternalSelectItem(ISelectableItem item, Boolean clearExistingSelection, Boolean select) at Infragistics.Win.UltraWinTree.UltraTree.Infragistics.Win.ISelectionManager.SelectItem(ISelectableItem item, Boolean clearExistingSelection) at Infragistics.Win.SelectionStrategySingle.OnMouseDown(ISelectableItem item, MouseMessageInfo& msginfo, Boolean forceDrag) at Infragistics.Win.SelectionStrategySingle.OnMouseDown(ISelectableItem item, MouseMessageInfo& msginfo) at Infragistics.Win.SelectionStrategySingle.OnMouseMessage(ISelectableItem item, MouseMessageInfo& msginfo) at Infragistics.Win.ControlUIElementBase.ProcessMouseDownHelper(Object sender, MouseEventArgs e) at Infragistics.Win.ControlUIElementBase.ProcessMouseDown(Object sender, MouseEventArgs e) at Infragistics.Win.Utilities.ProcessEvent(Control control, ProcessEvent eventToProcess, EventArgs e) at Infragistics.Win.UltraControlBase.OnMouseDown(MouseEventArgs e) at Infragistics.Win.UltraWinTree.UltraTree.OnMouseDown(MouseEventArgs e) at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks) 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)
The error indicates your data source has duplicate keys in it. Do you have two columns with the same key? Or a column and a child band that have the same key?
You seem to be saying that the new data structure you are binding to is exactly the same as the old one, so that seems like it should not be a problem. If it worked the first time, there's no reason why it would not work the second.
Hi, i had the same problem and your response was right, i wrote the dataset to a xml file and i realized that there were duplicate column names.