470,815 Members | 1,290 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,815 developers. It's quick & easy.

DataGrid exception 'System.NullReferenceException in method InitializeComponent

Using .NET C# installed Framework 1.1 with Service Pack 1

I have a MDI application in C# that contains 3 different forms. Form
1 has several controls one of which is a DataGrid control that works
fine. Form 2 has several controls, none of which ia a DatGrid
control. Form 3 has several controls, none of which as a DataGrid. In
this configuration everything compiles and runs fine. When I add a
DataGrid control to Form 3 I get the following error when running:

An unhandled exception of type 'System.NullReferenceException'
occurred in system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object.

I break at the exception and find it to be in the
InitializeComponent() method of Form 3 at the line

this.dataGrid1 = new System.Windows.Forms.DataGrid();

I then created a sampe app that contained an MDI with 3 forms. I put
a DataGrid control on 2 of the forms and I had no problems. I'm not
quite sure where to go from here.

Any ideas of why this is happening? this.dataGrid1 is undefined
before the new call which is what I expect. Why would I get a
NullReferenceException when newing the object?

Thanks,
Sarah
Jul 21 '05 #1
0 1632

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by CVerma | last post: by
4 posts views Thread by Frank | last post: by
2 posts views Thread by Flack | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.