I get this error at runtime, but not while debugging F5 style...
Error occurs when closing this form, which is an MDI Child form.
Everything works fine while in the form, but in runtime you can open it and close it immediately and get the unhandled exception
Unhandled exception...
e.Exception.Message = Cannot bind to the property or column pkid on the DataSource.
Parameter name: dataMember
e.Exception.StackTrace = at System.Windows.Forms.BindToObject.CheckBinding()
at System.Windows.Forms.Binding.SetListManager(BindingManagerBase bindingManagerBase)
at System.Windows.Forms.ListManagerBindingsCollection.AddCore(Binding dataBinding)
at System.Windows.Forms.BindingsCollection.Add(Binding binding)
at System.Windows.Forms.BindingContext.UpdateBinding(BindingContext newBindingContext, Binding binding)
at System.Windows.Forms.Control.UpdateBindings()
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.ListControl.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.RecreateHandleCore()
at System.Windows.Forms.ComboBox.RecreateHandleCore()
at System.Windows.Forms.ComboBox.SetAutoComplete(Boolean reset, Boolean recreate)
at System.Windows.Forms.ComboBox.OnDataSourceChanged(EventArgs e)
at System.Windows.Forms.ListControl.SetDataConnection(Object newDataSource, BindingMemberInfo newDisplayMember, Boolean force)
at System.Windows.Forms.ListControl.DataSourceDisposed(Object sender, EventArgs e)
at System.ComponentModel.Component.Dispose(Boolean disposing)
at System.Windows.Forms.BindingSource.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at System.ComponentModel.Container.Dispose(Boolean disposing)
at System.ComponentModel.Container.Dispose()
at TOM.frmPODetail.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at System.Windows.Forms.Form.WmClose(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)
e.Exception.Source = System.Windows.Forms
Why would i get an error that binding failed when 'closing' a form is beyond my knowledge, and more importantly I have to figure a way to fix it.
Below is my form closing event in case it is relevant, but I don't think so, as the included exception is not catching/triggering...
Private Sub frmPODetail_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Try
Me.POBindingSource.EndEdit()
Me.POLineBindingSource.EndEdit()
Catch ex As Exception
Dim reply As MsgBoxResult = MsgBox("Current row is in a bad state and cannot be saved, do you wish to exit and abort unsaved changes?", MsgBoxStyle.YesNoCancel + MsgBoxStyle.Critical)
If reply = MsgBoxResult.No Or reply = MsgBoxResult.Cancel Then
e.Cancel = True : Exit Sub
Else
e.Cancel = False : Exit Sub
End If
End Try
e.Cancel = Not HandleSaveChangesResponse("closing")
End Sub
I can't step into the code to see where it fails, as it doesn't fail in while f5'ing. Tried to get line numbers but that's failing.
Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
Dim sw As IO.StreamWriter
sw = New IO.StreamWriter("C:\tEMP\Unhandled-Detailed.txt", True)
Dim st As StackTrace = New StackTrace(e.Exception, True)
sw.WriteLine("Iterating through the Stack Frames...")
For Each sf As StackFrame In st.GetFrames
sw.Write("(Filename=" & sf.GetFileName & " Line " & sf.GetFileLineNumber() & ") Getmethod.module=" & sf.GetMethod.Module.ToString & " Getmethod=" & sf.GetMethod.DeclaringType.FullName.ToString & "." & sf.GetMethod.Name.ToString & vbCrLf)
Next
sw.Write(vbCrLf & vbCrLf)
sw.Close()
sw.Dispose()
Process.Start("C:\tEMP\Unhandled-Detailed.txt")
End Sub
outputs...
Iterating through the Stack Frames...
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.BindToObject.CheckBinding
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Binding.SetListManager
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ListManagerBindingsCollection.AddCore
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.BindingsCollection.Add
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.BindingContext.UpdateBinding
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control.UpdateBindings
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control.OnBindingContextChanged
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ListControl.OnBindingContextChanged
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control.CreateControl
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control.RecreateHandleCore
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ComboBox.RecreateHandleCore
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ComboBox.SetAutoComplete
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ComboBox.OnDataSourceChanged
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ListControl.SetDataConnection
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.ListControl.DataSourceDisposed
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Component.Dispose
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.BindingSource.Dispose
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Component.Dispose
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Container.Dispose
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Container.Dispose
(Filename= Line 0) Getmethod.module=TOM.exe Getmethod=TOM.frmPODetail.Dispose
(Filename= Line 0) Getmethod.module=System.dll Getmethod=System.ComponentModel.Component.Dispose
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Form.WmClose
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.Control+ControlNativeWindow.WndProc
(Filename= Line 0) Getmethod.module=System.Windows.Forms.dll Getmethod=System.Windows.Forms.NativeWindow.Callback
Any help would be greatly appreciated.