[Mono-bugs] [Bug 466605] New: NullReferenceException when setting ForeColor and BackColor of a ListViewSubItem

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Thu Jan 15 16:26:03 EST 2009


           Summary: NullReferenceException when setting ForeColor and
                    BackColor of a ListViewSubItem
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.2.x
          Platform: i586
        OS/Version: openSUSE 10.2
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Windows.Forms
        AssignedTo: mono-bugs at lists.ximian.com
        ReportedBy: rrussell at franticfilms.com
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---

Description of Problem:

The problem occurs when creating a new ListViewSubItem using the default
constructor. Here is the Mono ListViewSubItem source code for the constructors:

public ListViewSubItem ()

public ListViewSubItem (ListViewItem owner, string text)
    : this (owner, text, Color.Empty,
        Color.Empty, null)

public ListViewSubItem (ListViewItem owner, string text, Color foreColor,
            Color backColor, Font font)
    this.owner = owner;
    Text = text;
    this.style = new SubItemStyle (foreColor,
        backColor, font);

The problem is that when the default constructor is used, the private member
'style' doesn't get initialized. Then when you go to set the ForeColor or
BackColor, 'style' is null, and thus you get the NullReferenceException. I
imagine you would get the same results if you were getting the ForeColor or
BackColor as well.

The workaround I'm using is to pass Null for the owner and an empty string for
the text to the overloaded ListViewSubItem constructor.

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

More information about the mono-bugs mailing list