Has this happened to anyone before and what did you do? I am opening and closing forms and am executing the code in CloseWinPart. When I get to the line of code "panel.Controls.Remove(part); (am using C#) I get the message "ArgumentException was unhandled". Now, I don't get this for every form just a few. I have stepped through everything, for the forms that work and the ones that don't work and all looks similar, except for some give me the error. I have even trashed a form and started again and I still get the error. I have checked the methods GetIdValue in the WinPart of the form and GetIdValue in the BusinessObject and all is correct. Here is the information that is stored to clipboard when I get the error:
System.ArgumentException was unhandled
Message="Cannot bind to the property or column Description on the DataSource.\r\nParameter name: dataMember"
Source="System.Windows.Forms"
ParamName="dataMember"
StackTrace:
at System.Windows.Forms.BindToObject.CheckBinding()
at System.Windows.Forms.BindToObject.SetBindingManagerBase(BindingManagerBase lManager)
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.Control.OnParentBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.set_BindingContextInternal(BindingContext value)
at System.Windows.Forms.ContainerControl.set_BindingContext(BindingContext value)
at System.Windows.Forms.ContainerControl.get_BindingContext()
at System.Windows.Forms.Control.get_BindingContextInternal()
at System.Windows.Forms.Control.get_BindingContext()
at System.Windows.Forms.Control.UpdateBindings()
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e)
at System.Windows.Forms.Control.AssignParent(Control value)
at System.Windows.Forms.Control.ControlCollection.Remove(Control value)
at BASWin.MainForm.CloseWinPart(Object sender, EventArgs e) in D:\Visual Studio 2008\CSLA Framework\BAS\BASWin\MainForm.cs:line 311
at BASWin.WinPart.Close() in D:\Visual Studio 2008\CSLA Framework\BAS\BASWin\WinPart.cs:line 74
at BASWin.InventoryIndicatorEditForm.closeButton_Click(Object sender, EventArgs e) in D:\Visual Studio 2008\CSLA Framework\BAS\BASWin\Operations\Sources\InventoryIndicatorEditForm.cs:line 113
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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.Run(Form mainForm)
at BASWin.Program.Main() in D:\Visual Studio 2008\CSLA Framework\BAS\BASWin\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
I have been battling with this for a couple of days and cannot figure it out. I have created other BusinessObjects and forms and they have been ok, and then created another set and got the error. Any ideas would be greatly appreciated. I have a feeling this is an "ah duh" error. It has got to be so simple that I am missing something.
Thank you in advance for your assistance if fixing this error!
Keith
You aren't alone. I've recently experienced the exact same error when using WinPart. My form was working fine, but for some reason now I'm getting the same exception at "panel.Controls.Remove(part)" (I'm using VB).
I'm also looking for a suggestion into what may be causing this. It's very frustrating...
As luck would have, moments after my last previous post I stumbled upon the fix for my particular issue.
The problem I had was that the ErrorProvider on the form was not bound against the datasource. Check the ErrorProvider on your form, and make sure that it is bound to the same DataSource that the form is bound to. That fixed the problem on my end.
Good luck.
I knew it was an "ah duh". That was it!! It is those simple, obvious things that get me every time.
Keith
After reading Rocky's advice on building a UI using user controls instead of forms in chapter 9 I decided to model my UI on the PTracker model.
I am also "pulling my hair out" with this same problem and I don't understand the solution used by the others here to resolve it. I used CSLAGen to create my objects and they do not have a reference to ErrorProvider.
In CloseWinPart, the line: " Panel1.Controls.Remove(part) " generates the following exception.
System.ArgumentException was unhandled
Message="Cannot bind to the property or column BankShortName on the DataSource. Parameter name: dataMember"
ParamName="dataMember"
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.BindToObject.CheckBinding() at System.Windows.Forms.BindToObject.SetBindingManagerBase(BindingManagerBase lManager) 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.Control.OnParentBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.set_BindingContextInternal(BindingContext value) at System.Windows.Forms.ContainerControl.set_BindingContext(BindingContext value) at System.Windows.Forms.ContainerControl.get_BindingContext() at System.Windows.Forms.Control.get_BindingContextInternal() at System.Windows.Forms.Control.get_BindingContext() at System.Windows.Forms.Control.UpdateBindings() at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.OnParentBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.OnBindingContextChanged(EventArgs e) at System.Windows.Forms.Control.AssignParent(Control value) at System.Windows.Forms.Control.ControlCollection.Remove(Control value) at OffsetInterestWin.MainForm.CloseWinPart(Object sender, EventArgs e) in C:\Users\Warren\Documents\DOTNET\OffsetInterest\OffsetInterestWin\MainForm.vb:line 470 at OffsetInterestWin.WinPart.Close() in C:\Users\Warren\Documents\DOTNET\OffsetInterest\OffsetInterestWin\WinPart.vb:line 56 at OffsetInterestWin.BankEdit.CloseButton_Click(Object sender, EventArgs e) in C:\Users\Warren\Documents\DOTNET\OffsetInterest\OffsetInterestWin\BankEdit.vb:line 87 at System.Windows.Forms.Control.OnClick(EventArgs e) at System.Windows.Forms.Button.OnClick(EventArgs e) at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ButtonBase.WndProc(Message& m) at System.Windows.Forms.Button.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.Run(ApplicationContext context) at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine) at OffsetInterestWin.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
InnerException:
Any help is greatly appreciated.
I'm new to OOP, CSLA and CSLAGen and sometimes it is a bit overwhelming but I continue to make progress so I'm staying the course with CSLA.
Adding ErrorProvider also solved my problem - yipee.
Copyright (c) Marimer LLC