When I am refreshing a databinding on a grid I am getting a;
A first chance exception of type 'System.ArgumentException' occurred in Infragistics2.Shared.v10.1.dll
A message box pops up that says "Key Already Exists Paramater Name: Key
The first time I set the databinding it works fine and show the rows, if i try to set it again it blows up. I have tried setting it to nothing first but that didnt work. Its just a simple refresh because the list its bound to may have added or removed rows.
How do I troubleshoot this?
I think refreshing like that is not necessary. If you bind a list to the grid and add or delete items, the grid should show the changes. However, not any list supports that, and more specifically, only IBindingList does.
Instead of binding your list directly do this:
var bindingList = new BindingList<myEntity>(myEntitylist);
grid.DataSource = bindingList;
Now any delete or insert in your original list should immediately be seen on the grid.
If you still want to refresh manually, just call grid.Rows.Refresh(RefreshRow.ReloadData);
I'm not actually deleting items out of my list, I set a deletedflag = True on one of the objects in the list, then I have a property that uses LINQ to return a list of valid items (Not deleted) and bind to that. When I set deletedflag = True to an item, it does not remove from the grid unless I refersh
I use this technique all throughout my project but this particular grid configuration is giving me problems.
I tried what u suggested and got the exact same error.
If you still get the error, there are some things that can cause that:
1. Using threading without safe invocation.
2. Adding columns manually.
3. Not using the latest service release. The last one was just released 5 days ago.
Can you post the call stack you get?
All my columns are added at design time. The service release did not fix it.
Call stack below.
"System.ArgumentException: Key already exists Parameter name: Key at Infragistics.Shared.KeyedSubObjectsCollectionBase.ValidateKeyDoesNotExist(String key, IKeyedSubObject ignoreObject) at Infragistics.Shared.KeyedSubObjectsCollectionBase.ValidateKeyDoesNotExist(String key) at Infragistics.Win.AppearancesCollection.Add(String key) at CMMS.UI.Scheduling.frmScheduleWeekly.grdWOs_InitializeLayout(Object sender, InitializeLayoutEventArgs e) in D:\CMMS\CMMS.UI\CMMS.UI\Scheduling\frmScheduleWeekly.vb:line 58 at Infragistics.Win.UltraWinGrid.UltraGrid.OnInitializeLayout(InitializeLayoutEventArgs e) at Infragistics.Win.UltraWinGrid.UltraGrid.FireEvent(GridEventIds id, EventArgs e) at Infragistics.Win.UltraWinGrid.UltraGrid.FireInitializeLayout(InitializeLayoutEventArgs e) at Infragistics.Win.UltraWinGrid.UltraGridLayout.ApplyLoadedBands() 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.SetDataBindingHelper(Object dataSource, String dataMember, Boolean hideNewColumns, Boolean hideNewBands) at Infragistics.Win.UltraWinGrid.UltraGridBase.SetDataBinding(Object dataSource, String dataMember, Boolean hideNewColumns, Boolean hideNewBands) at Infragistics.Win.UltraWinGrid.UltraGridBase.SetDataBinding(Object dataSource, String dataMember, Boolean hideNewColumns) at CMMS.UI.Scheduling.frmScheduleWeekly.Fillform() in D:\CMMS\CMMS.UI\CMMS.UI\Scheduling\frmScheduleWeekly.vb:line 25 at CMMS.UI.Scheduling.frmScheduleWeekly.WoRemove() in D:\CMMS\CMMS.UI\CMMS.UI\Scheduling\frmScheduleWeekly.vb:line 200 at CMMS.UI.Scheduling.frmScheduleWeekly.RemoveFromScheduleToolStripMenuItem_Click(Object sender, EventArgs e) in D:\CMMS\CMMS.UI\CMMS.UI\Scheduling\frmScheduleWeekly.vb:line 205 at System.Windows.
Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.ToolStripDropDown.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.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.RunDialog(Form form) at System.Windows.Forms.Form.ShowDialog(IWin32Window owner) at System.Windows.Forms.Form.ShowDialog() at CMMS.Exe.Startup.Main() in D:\CMMS\CMMS.EXE\CMMS.Exe\Startup.vb:line 29"
MIke, you nailed it. I didnt realize the InitializeLayout fired everytime the datasource was set and It was trying to add a duplicate appearance.
You guys are awesome Thanks!