List View variable throwing NullException

  • Thread starter Thread starter Miesha.James
  • Start date Start date
M

Miesha.James

Hello,

I've added a list view to a windows form and I want to add items and
subitems to the list at runtime. The problem that I have is that when
I try to use the list view control variable it throws the following
error

An unhandled exception of type 'System.NullReferenceException'
occurred in RcvrStatusTest.exe

Additional information: Object reference not set to an instance of an
object.


I created the list view control by using the design wizard. So, I
used the variable the was generated by the design wizard.

(exception thrown here) ListView1 = gcnew ListView(); (If I were to
comment out this line the exception will be thrown on the next line
that contains ListView1)

(Here)ListViewItem^ lviName= ListView1->Items->Add("Michael
Beasley");
lviName->SubItems->Add("101 Lance Court");
lviName->SubItems->Add("000-000-0000");

Does anyone have any suggestions?
 
Hello,

I've added a list view to a windows form and I want to add items and
subitems to the list at runtime. The problem that I have is that when
I try to use the list view control variable it throws the following
error

An unhandled exception of type 'System.NullReferenceException'
occurred in RcvrStatusTest.exe

Additional information: Object reference not set to an instance of an
object.


I created the list view control by using the design wizard. So, I
used the variable the was generated by the design wizard.

The wizard creates code to create subcontrols in InitializeComponent. If
you try using any of your child controls before InitializeComponent runs,
you'll have that error.
 
The wizard creates code to create subcontrols in InitializeComponent.  If
you try using any of your child controls before InitializeComponent runs,
you'll have that error.- Hide quoted text -

- Show quoted text -

Thank you so much Ben! I believe that has fixed the problem!
 
Back
Top