Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange behaviour with Datagrid

Status
Not open for further replies.

kevinf2349

Technical User
Sep 12, 2002
367
US
I must be doing something stupid but I can't figure out what it is

If I run the following code asis it works fine:

MsgBox("Add col1")
dt.Columns.Add(New DataColumn(System.String.Format("Column 0", 0), GetType(System.String)))
MsgBox("Add col2")
dt.Columns.Add(New DataColumn(System.String.Format("Column 1", 1), GetType(System.String)))
MsgBox("Add col3")
dt.Columns.Add(New DataColumn(System.String.Format("Column 2", 2), GetType(System.Int16)))
MsgBox("Add col4")
dt.Columns.Add(New DataColumn(System.String.Format("Column 3", 3), GetType(System.Int16)))
MsgBox("Add col5")
dt.Columns.Add(New DataColumn(System.String.Format("Column 4", 4), GetType(System.String)))
' MsgBox("new row")

If I comment out the msgbox statements and run the program it throws the following exception

An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module.

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

Any idea what I could be doing wrong?
 
Got it!

Silly me. I had a definition in the wrong place. Not sure why placing msgbox statements made it work, but it now functions correctly either way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top