Bug 472968

Summary: DataGridViewRowCollection.Insert is broken
Product: [Mono] Mono: Class Libraries Reporter: Mario Carrion <mcarrion>
Component: Windows.FormsAssignee: Forgotten User CRPsQFwJ3b <forgotten_CRPsQFwJ3b>
Status: RESOLVED FIXED QA Contact: Mono Bugs <mono-bugs>
Severity: Normal    
Priority: P5 - None CC: forgotten_CRPsQFwJ3b
Version: SVN   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: Beta-Customer Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Bug Depends on:    
Bug Blocks: 468504    
Attachments: Example.
Output
.NET Screenshot
Another example
Patch
Fix

Description Mario Carrion 2009-02-05 17:40:29 UTC
Created attachment 270515 [details]
Example.

1. Compile attached code.
2. click "Add row" button.
3. Crash.

.NET doesn't crash, see attached image to see behavior.
Comment 1 Mario Carrion 2009-02-05 17:41:10 UTC
Created attachment 270516 [details]
Output
Comment 2 Mario Carrion 2009-02-05 17:43:27 UTC
Created attachment 270519 [details]
.NET Screenshot
Comment 3 Mario Carrion 2009-02-05 18:04:17 UTC
Created attachment 270532 [details]
Another example 

This example is similar to previous one, but shows the issue in a different way, seems that DataGridViewRowCollection.Insert() should be using list.Insert instead of using list[]. 

(Would be awesome to attach several patches at same time in bugzilla)
I wrote an attempt to patch continue reading in next comment.
Comment 4 Mario Carrion 2009-02-05 18:06:13 UTC
Created attachment 270536 [details]
Patch

However with this patch, I got the following exception after OnPaint, so I'm sure I'm missing something really important.

mario@malakarma:~/trashme> gmcs -r:System,System.Windows.Forms,System.Drawing dgrid1.cs && mono --debug dgrid1.exe 
System.ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
Parameter name: index
2
  at System.Collections.ArrayList.ThrowNewArgumentOutOfRangeException (System.String name, System.Object actual, System.String message) [0x00000] in /home/mario/repository/mcarrion/mcs/class/corlib/System.Collections/ArrayList.cs:3258 
  at System.Collections.ArrayList.get_Item (Int32 index) [0x00013] in /home/mario/repository/mcarrion/mcs/class/corlib/System.Collections/ArrayList.cs:2649 
  at System.Windows.Forms.DataGridViewRowCollection.get_Item (Int32 index) [0x00000] in /home/mario/repository/mcarrion/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewRowCollection.cs:82 
  at System.Windows.Forms.DataGridViewRow.GetState (Int32 rowIndex) [0x0004c] in /home/mario/repository/mcarrion/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridViewRow.cs:445 
  at System.Windows.Forms.DataGridView.OnPaint (System.Windows.Forms.PaintEventArgs e) [0x0036c] in /home/mario/repository/mcarrion/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs:4583 
  at System.Windows.Forms.Control.WmPaint (System.Windows.Forms.Message& m) [0x0008a] in /home/mario/repository/mcarrion/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:5561 
  at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x0016c] in /home/mario/repository/mcarrion/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:5319 
  at System.Windows.Forms.DataGridView.WndProc (System.Windows.Forms.Message& m) [0x00000] in /home/mario/repository/mcarrion/mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs:5521 
  at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000] in /home/mario/repository/mcarrion/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:234 
  at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x00000] in /home/mario/repository/mcarrion/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Control.cs:215 
  at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) [0x00085] in /home/mario/repository/mcarrion/mcs/class/Managed.Windows.Forms/System.Windows.Forms/NativeWindow.cs:242
Comment 5 Forgotten User CRPsQFwJ3b 2009-02-05 18:28:36 UTC
Fixed in trunk in r125900 and in 2.4 branch in r125901.

You are right the problem was indeed what you say bundles with some redraw issues. Patch attached FYI.
Comment 6 Forgotten User CRPsQFwJ3b 2009-02-05 18:29:40 UTC
Created attachment 270550 [details]
Fix
Comment 7 Forgotten User CRPsQFwJ3b 2009-02-05 18:29:58 UTC
Marking as fixed.
Comment 8 Mario Carrion 2009-02-05 20:17:13 UTC
Thanks for the quick fix!