The given key was not present in the dictionary error


Author
Message
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi,



I am working with a DataGridView in a child form, if I cancel the childform with the follwing code:



DialogResult = Windows.Forms.DialogResult.Cancel




Then I get the following exception:





KeyNotFoundException

The given key was not present in the dictionary.



Source : mscorlib



Stack Trace:

at System.ThrowHelper.ThrowKeyNotFoundException()

at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

at MicroFour.StrataFrame.Business.BusinessLayer.get__CurrentDataTable(Boolean IsSharedTable)

at MicroFour.StrataFrame.Business.BusinessBindingSource.RemoveBOHandlers()

at MicroFour.StrataFrame.Business.BusinessBindingSource.Dispose(Boolean disposing)

at System.ComponentModel.Component.Dispose()

at System.ComponentModel.Container.Dispose(Boolean disposing)

at System.ComponentModel.Container.Dispose()

at CardTrackingSystem.frmActivateCardsItems.Dispose(Boolean disposing) in E:\Visual Studio 2008 Projects\StrataFrame\Card Tracking System Projects\CardTrackingSystem.NET\CTS Solution\Card Tracking System\Dialogs\Transaction Forms\Activate Cards\frmActivateCardsItems.Designer.vb:line 10

at System.Windows.Forms.Form.Close()

at MicroFour.StrataFrame.UI.Windows.Forms.ChildFormDialog.ShowDialog(Object[] Arguments)

at MicroFour.StrataFrame.UI.Windows.Forms.ChildFormDialog.ShowDialog()

at CardTrackingSystem.frmActivateCards.cmdAddCards_Click(Object sender, EventArgs e) in E:\Visual Studio 2008 Projects\StrataFrame\Card Tracking System Projects\CardTrackingSystem.NET\CTS Solution\Card Tracking System\Dialogs\Transaction Forms\Activate Cards\frmActivateCards.vb:line 800

at System.EventHandler.Invoke(Object sender, EventArgs e)

at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)

at System.Windows.Forms.ToolStripButton.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.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.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 DataGridView is being populated with a BBS and the error only happens if the grid has some data. I don't know what "Key" it may be looking for? Also I would like to note that the BO assigned to the BBS has come Custom Field Properties which are not used in the DataGridView.

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Before we get into samples, for grins, in the OnFormClosing of the form, remove the binding from the grid to see if the error goes away.
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Trent,



Thanks for the inside, I am really going nuts with this DataGridView control.



I tried this code and it is not working:



Protected Overrides Sub OnFormClosing(ByVal e As System.Windows.Forms.FormClosingEventArgs)

MyBase.OnFormClosing(e)

Me.DataGridView1.DataSource = Nothing

End Sub





I tried the code before and after MyBase call. It is this what you suggested?

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Well, to isolate the issue, just add a temp button to remove this and then close the dialog. FWIW, this is actually something that is done often, so I know it will work. But like anything else with grids, environment and code always plays a factor.



If you have any refresh code anywhere in your dialog, this could cause a potential issue as well if it is being called during the closing of the dialog.
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Humm, I added the butting and called the same code:





Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Me.DataGridView1.DataSource = Nothing

End Sub







Trent L. Taylor (06/01/2009)
Before we get into samples, for grins, in the OnFormClosing of the form, remove the binding from the grid to see if the error goes away.


When you say "remove the binding from the grid" you meant Me.DataGridView1.DataSource = Nothing?

Edhy Rijo

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Trent,



Playing with this a bit, I came up with the following code which seams to work:





Protected Overrides Sub OnFormClosing(ByVal e As System.Windows.Forms.FormClosingEventArgs)

MyBase.OnFormClosing(e)



'-- Remove the DataSource from the grid to avoid the error while closing the form.

' Error:

' KeyNotFoundException

' The given key was not present in the dictionary.

Me.DataGridView1.DataSource = Nothing

Me.BusinessBindingSource1.Dispose()

End Sub





Do you see any technical problem with this code?

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
That should work fine. Run with it and let's see if it resolves your issue.
Larry Caylor
Larry Caylor
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Awaiting Activation
Posts: 592, Visits: 3.7K
I just ran into the same issue after upgrading an existing application to v 1.6.7. I'm using the Infragistics grid. The workaround of unbinding the grid/s from the datasource works but something in the new version of SF introduced this since the app has worked perfectly for months on the previous version of SF.
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Larry,



My guess is that something changed in the BBS which may be causing this behavior.

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
The BBS did change as there was a memory leak. The memory leak ensures that the internal objects are disposed of...so there was actually a leak. I will see if I can reproduce the exception.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search