P
prodata
I'm trying to use a DGV bound to a datatable as the data source that's
throwing a NullReferenceException (under VB2005) that I don't
understand. Here's the relevant block of code
With DataGridView1
.DataSource = dtRawLeWLData
.DefaultCellStyle.NullValue = "-"
.Columns("DirX").Visible = False
.Columns("DirY").Visible = False
.Columns("DateTime").Width = 30 ' (HERE'S THE PROBLEM
LINE)
End With
If I comment out the line setting the width of column
"DateTime" (which is a valid column name) then the code runs
perfectly. But with the line left in there's an NRE error. But the
lines above the Width setting one are presumably referencing the same
object so why does trying to set the column width throw the NRE error?
throwing a NullReferenceException (under VB2005) that I don't
understand. Here's the relevant block of code
With DataGridView1
.DataSource = dtRawLeWLData
.DefaultCellStyle.NullValue = "-"
.Columns("DirX").Visible = False
.Columns("DirY").Visible = False
.Columns("DateTime").Width = 30 ' (HERE'S THE PROBLEM
LINE)
End With
If I comment out the line setting the width of column
"DateTime" (which is a valid column name) then the code runs
perfectly. But with the line left in there's an NRE error. But the
lines above the Width setting one are presumably referencing the same
object so why does trying to set the column width throw the NRE error?