How to delete all rows in databound datagridview?

I am trying to clear all rows in a databound datagridview. Tried

Me.AppointmentsBindingSource.Clear()

but got "Cannot clear this list." Full exception below

Any help appreciated.

GS
Exception was unhandled
Message="Cannot clear this list."
Source="System.Data"
StackTrace:
at System.Data.DataView.System.Collections.IList.Clear()
at System.Windows.Forms.BindingSource.Clear()
at VBNMNew.Rosters.DeleteFromTemplateButton_Click(Object sender, EventArgs e) in C:\Documents and Settings\Geoffrey Stokeld\My Documents\Visual Studio 2005\Projects\VBNMNew\VBNMNew\Rosters.vb:line 28
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 VBNMNew.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
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()

[2906 byte] By [GS] at [2007-12-17]
# 1
Found this works for me.

Do While Me.AppointmentsBindingSource.Count <> 0 'removes displayed rows

Me.AppointmentsBindingSource.MoveFirst()

Me.AppointmentsBindingSource.RemoveCurrent()

Loop

Me.AppointmentsBindingSource.EndEdit() 'saves to database

Me.AppointmentsTableAdapter.Update(Me.VBNMDATADataSet.Appointments)

GS at 2007-10-6 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 2
For me it was simple.
Your Datagridview was probably databound.

Me.AppointmentsBindingSource.DataSource = nothing '(or null in c#)

That's what made it work for me!

Me.AppointmentsBindingSource.Rows.Clear then should work.

Damian

theDamian at 2007-10-6 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...
# 3

I tried this and it also works fine.

if (userTable != null)

{

userTable.Clear();

}

userDataGridView.DataSource = null;

userDataGridView.Rows.Clear();

userDataGridView.Refresh();

jdkulkarni at 2007-10-6 > top of Msdn Tech,Visual Studio Express Editions,Visual Basic 2005 Express Edition...