Bug 3125 - Setting Value on a DataGridViewRow with -1 rowIndex crashes the application.
Summary: Setting Value on a DataGridViewRow with -1 rowIndex crashes the application.
Alias: None
Product: Class Libraries
Classification: Mono
Component: Windows.Forms ()
Version: 2.10.x
Hardware: Other All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-01-28 07:52 UTC by sectroyer
Modified: 2012-08-10 15:37 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Sample code that illustrates the problem (80.06 KB, application/x-zip-compressed)
2012-01-28 07:52 UTC, sectroyer

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description sectroyer 2012-01-28 07:52:12 UTC
Created attachment 1286 [details]
Sample code that illustrates the problem

Description of Problem:
If DataGridViewRow is added to DataGridView and then removed it has -1 index. Setting Value on it crashes mono. Nevertheless the same code under .NET Framework works fine.

Steps to reproduce the problem:
1. Luanch Sample Application.
2. Click "Change" button.

Actual Results:
Application crash

Expected Results:
Nothing should happen.

How often does this happen? 

Additional Information:

System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: rowIndex
  at System.Windows.Forms.DataGridViewCell.GetValue (Int32 rowIndex) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.DataGridViewCell.get_Value () [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.DataGridViewCell.SetValue (Int32 rowIndex, System.Object value) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.DataGridViewCell.set_Value (System.Object value) [0x00000] in <filename unknown>:0 
  at mtm.Controls.DataGridViewStatusCell.set_status (Status value) [0x00000] in <filename unknown>:0 
  at mtm.Controls.MirrorTaskRow.SetStatus (Status status) [0x00000] in <filename unknown>:0 
  at datagridRowIndex.Form1.button2_Click (System.Object sender, System.EventArgs e) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.OnClick (System.EventArgs e) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Button.OnClick (System.EventArgs e) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ButtonBase.OnMouseUp (System.Windows.Forms.MouseEventArgs mevent) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Button.OnMouseUp (System.Windows.Forms.MouseEventArgs mevent) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.WmLButtonUp (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.ButtonBase.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Button.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control+ControlWindowTarget.OnMessage (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.Control+ControlNativeWindow.WndProc (System.Windows.Forms.Message& m) [0x00000] in <filename unknown>:0 
  at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) [0x00000] in <filename unknown>:0
Comment 1 Sesef 2012-07-31 17:08:47 UTC
In NET Framwork when index = -1, DataGridView field is null also. In MONO DataGridView is set to DataGrid where cell was added I think this is a problem here.
Comment 2 Miguel de Icaza [MSFT] 2012-08-10 15:37:00 UTC
Applied the fix