Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

DataGridView crashes program when User deletes a row - exception is "Index was out of range. Must be non-negative and less than the size of the collection."

$
0
0

I have a fairly simple data grid view which is bound to a BindingSource which is connected to a dataset.  I have several events connected to the grid, particularly the UserDeletingRow event for asking the user if they want to delete a row.  This event fires and steps through to the end of the event with no problem, when the user selects a row in the grid and presses the Delete key.  The program then immediately throws an error with the following stack trace, none of which involves my code.  The stack trace is shown below.  The data itself has 6 rows in the with the middle one being deleted.  When stepping through with the debugger - I end up in Assembly code when the exception is thrown.  Does any one have any suggestions or a work-around for this?  This is such simple functionality, I can't understand how this cannot be working after all this time.  The project is compiled against .Net 4.0 in Visual Basic.

>mscorlib.dll!System.Collections.ArrayList.this[int].get(int index) + 0x74 bytes

 System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRowCollection.SharedRow(int rowIndex) + 0xe bytes
 System.Windows.Forms.dll!System.Windows.Forms.DataGridViewRowCollection.this[int].get(int index = 1) + 0x27 bytes
 System.Windows.Forms.dll!System.Windows.Forms.DataGridView.ProcessDeleteKey(System.Windows.Forms.Keys keyData) + 0x19e bytes
 System.Windows.Forms.dll!System.Windows.Forms.DataGridView.ProcessDataGridViewKey(System.Windows.Forms.KeyEventArgs e) + 0x101 bytes
 System.Windows.Forms.dll!System.Windows.Forms.DataGridView.OnKeyDown(System.Windows.Forms.KeyEventArgs e = {KeyData = RButton | MButton | Back | Space}) + 0x104 bytes
 System.Windows.Forms.dll!System.Windows.Forms.Control.ProcessKeyEventArgs(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) + 0x3f8 bytes
 System.Windows.Forms.dll!System.Windows.Forms.DataGridView.ProcessKeyEventArgs(ref System.Windows.Forms.Message m) + 0x244 bytes
 System.Windows.Forms.dll!System.Windows.Forms.Control.ProcessKeyMessage(ref System.Windows.Forms.Message m) + 0x39 bytes
 System.Windows.Forms.dll!System.Windows.Forms.Control.WmKeyChar(ref System.Windows.Forms.Message m = {System.Windows.Forms.Message}) + 0x18 bytes
 System.Windows.Forms.dll!System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message m) + 0x7c2 bytes
 System.Windows.Forms.dll!System.Windows.Forms.DataGridView.WndProc(ref System.Windows.Forms.Message m) + 0x10a bytes
 System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x11 bytes
 System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x39 bytes
 System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.DebuggableCallback(System.IntPtr hWnd, int msg = 256, System.IntPtr wparam, System.IntPtr lparam) + 0x5e bytes
 [Native to Managed Transition]
 [Managed to Native Transition]
 System.Windows.Forms.dll!System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(System.IntPtr dwComponentID, int reason = -1, int pvLoopData = 0) + 0x24d bytes
 System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.WinFormsAppContext})+ 0x155 bytes
 System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x4a bytes
 System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.ApplicationContext context) + 0x18 bytes
 Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun() + 0x7f bytes
 Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel() + 0x103 bytes
 Microsoft.VisualBasic.dll!Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(string[] commandLine) + 0x311 bytes


Neil M. Johnson


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>