all groups > visual c > march 2007 >
You're in the

visual c

group:

List View variable throwing NullException


List View variable throwing NullException Miesha.James NO[at]SPAM gmail.com
3/28/2007 2:43:55 PM
visual c:
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?
Re: List View variable throwing NullException Ben Voigt
3/28/2007 5:15:25 PM

[quoted text, click to view]

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.

Re: List View variable throwing NullException Miesha.James NO[at]SPAM gmail.com
3/28/2007 7:38:45 PM
[quoted text, click to view]

Thank you so much Ben! I believe that has fixed the problem!
AddThis Social Bookmark Button