[Mono-bugs] [Bug 600786] New: DataGridView: NullReferenceException when trying to set a Cell value after DataGridViewRow.CreateCells

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Apr 29 03:54:43 EDT 2010



           Summary: DataGridView: NullReferenceException when trying to
                    set a Cell value after DataGridViewRow.CreateCells
    Classification: Mono
           Product: Mono: Runtime
           Version: 2.6.x
          Platform: x86-64
        OS/Version: Windows 7
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: JIT
        AssignedTo: lupus at novell.com
        ReportedBy: jm at grassau.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: Development
           Blocker: No

Description of Problem:

After creating a new DataGridViewRow and calling DataGridViewRow.CreateCells(),
you should be able to set the row's cell values. Mono, however, throws a

Steps to reproduce the problem:

1. Create a Form ("Form1") with a DataGridView ("DataGridView1") and a Button

2. Add the following code to the Button1_Click sub:

    Dim TextBoxColumn1 As New DataGridViewTextBoxColumn
    TextBoxColumn1.Name = "Text"

    Dim Row1 As New DataGridViewRow()
    Row1.Cells(0).Value = "Cell"

Actual Results:

If the application is run in Visual Studio 2008 without Mono, and Button1 is
clicked, a DataGridView with one column ("Text") and one Row ("Cell") is shown.
No exception is thrown. 

However, if it is run with Mono, the following exception occurs when the button
is clicked:

System.NullReferenceException: Object reference not set to an instance of an

  at System.Windows.Forms.DataGridViewCell.GetValue (Int32 rowIndex) [0x00042]

  at System.Windows.Forms.DataGridViewCell.get_Value () [0x00000] in

  at System.Windows.Forms.DataGridViewCell.SetValue (Int32 rowIndex, 
System.Object value) [0x00000] in

  at System.Windows.Forms.DataGridViewCell.set_Value (System.Object value)
[0x00000] in

  at DgvMonoTest.Form1.Button1_Click (System.Object sender, System.EventArgs
e)[0x00000] in <filename unknown>:0

Apparently, when the code tries to set "Row1.Cells(0).Value", Mono's
"DataGridViewCell.SetValue" calls "DataGridViewCell.GetValue". The value,
however, is Nothing, so the exception is thrown (but why should .GetValue be
necessary to set the value? Maybe there's simply missing a "If value Is
Nothing" line in DataGridViewCell.SetValue).

Expected Results:

No exception should be thrown. Instead, the row should be added to the

How often does this happen? 


Additional Information:

As a workaround, instead of creating a DataGridViewRow, the following code

    Dim obj(0) As Object
    obj(0) = "Cell"

Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the mono-bugs mailing list