Click here to Skip to main content
15,884,933 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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...
VB
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.

VB
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.
Posted
Updated 30-Sep-14 5:31am
v2

1 solution

Ok, just took a databound combobox that I was using for a search filter, made the following change, and now I don't get the error.

Changed from using a table adapter and binding source to grabbing a data table in code
Private Sub FillVendorSearchCombobox()
   Try
      Me.cmbSearchVendor.DataSource = DAL.VendorDataTableAllRecords
      cmbSearchVendor.ValueMember = "Pkid"
      cmbSearchVendor.DisplayMember = "Name"
   Catch ex As Exception
      MessageBox.Show("Can not open connection to populate the Service Crew Filter Combobox ! ")
   End Try
End Sub


from a function
VB
Public Function VendorDataTableAllRecords() As dsTOM.VendorDataTable
    Dim ta As New dsTOMTableAdapters.VendorTableAdapter
    Return ta.GetData
End Function
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900