[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


http://bugzilla.novell.com/show_bug.cgi?id=600786

http://bugzilla.novell.com/show_bug.cgi?id=600786#c0


           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
NullReferenceException


Steps to reproduce the problem:

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

2. Add the following code to the Button1_Click sub:

    Dim TextBoxColumn1 As New DataGridViewTextBoxColumn
    TextBoxColumn1.Name = "Text"
    DataGridView1.Columns.Add(TextBoxColumn1)

    Dim Row1 As New DataGridViewRow()
    Row1.CreateCells(DataGridView1)
    Row1.Cells(0).Value = "Cell"
    DataGridView1.Rows.Add(Row1)


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
object

  at System.Windows.Forms.DataGridViewCell.GetValue (Int32 rowIndex) [0x00042]
in
C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.3\mcs\class\Managed.Windows.Forms\System.Windows.Forms\DataGridViewCell.cs:930

  at System.Windows.Forms.DataGridViewCell.get_Value () [0x00000] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.3\mcs\class\Managed.Windows.Forms\System.Windows.Forms\DataGridViewCell.cs:382

  at System.Windows.Forms.DataGridViewCell.SetValue (Int32 rowIndex, 
System.Object value) [0x00000] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.3\mcs\class\Managed.Windows.Forms\System.Windows.Forms\DataGridViewCell.cs:1326

  at System.Windows.Forms.DataGridViewCell.set_Value (System.Object value)
[0x00000] in
C:\cygwin\tmp\monobuild\build\BUILD\mono-2.6.3\mcs\class\Managed.Windows.Forms\System.Windows.Forms\DataGridViewCell.cs:385

  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
DataGridView. 



How often does this happen? 

Always.


Additional Information:

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

    Dim obj(0) As Object
    obj(0) = "Cell"
    DataGridView1.Rows.Add(obj(0))

-- 
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