Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Calling BindingSource.AddNew() causes System.NotSupportedException

My form 'StartForm' has a BindingSource object called 'SharedBindingSource' which was added using the Form Designer with the AllowNew property set to True and the DataSource property assigned to my typed DataSet . The tped DataSet has some default column values.

When the form loads I call 'Me.SharedBindingSource.AddNew()' as I want to display in my form a single row of data with the default column values. However, on calling the method I always get the exception below.

I have used this before in a similar project but I cannot tell why it is not working this time around.

Exception details:

System.NotSupportedException was unhandled by user code
Message="Specified method is not supported."
Source="System.Data"
StackTrace:
at System.Data.DataViewManager.System.ComponentModel.IBindingList.AddNew()
at System.Windows.Forms.BindingSource.AddNew()
at WinPresentationLayer.StartForm.StartForm_Load(Object sender, EventArgs e) in D:\WinPresentationLayer\Forms\StartForm.vb:line 15
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.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)

Thanks
Mark
[2062 byte] By [mjtech] at [2007-11-11 8:45:11]
# 1 Re: Calling BindingSource.AddNew() causes System.NotSupportedException
I discovered that the exception was raised because I had not yet assigned a value to the BindingSource.DataMember property.

I had intended/hoped that AddNew() would add a new row to each DataTable in the DataSet but obviously it only acts upon the assigned DataMember.
mjtech at 2007-11-11 21:47:05 >