PC Review


Reply
Thread Tools Rate Thread

DateGridView NRE Error

 
 
prodata
Guest
Posts: n/a
 
      15th Apr 2010
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?
 
Reply With Quote
 
 
 
 
prodata
Guest
Posts: n/a
 
      16th Apr 2010
No thoughts anyone please?

JGD
 
Reply With Quote
 
Andrew Morton
Guest
Posts: n/a
 
      16th Apr 2010
prodata wrote:
> No thoughts anyone please?


You could try changing the name of the "DateTime" column in case it somehow
conflicts with the name of the DateTime structure. Or list what the computer
"thinks" the columns are called and see if it agrees with what you think it
should be. Or use the number of the column.

Andrew


 
Reply With Quote
 
prodata
Guest
Posts: n/a
 
      16th Apr 2010
Thanks but I've previously tried using the column number instead of
name and it makes no difference.

I was wondering whether trying to set the column width is somehow a
true runtime instruction (ie active when the DGV is actually being
drawn) whereas things like setting the visibility of individual
columns is just setting a pre-draw-time property. So what I might need
to do is to try and set the column width at some later point in the
DGV's life-cycle, but I'm not sure how to do this. (No I don't think
it's a very convincing idea either, but I'm struggling...)
 
Reply With Quote
 
Andrew Morton
Guest
Posts: n/a
 
      16th Apr 2010
prodata wrote:
> Thanks but I've previously tried using the column number instead of
> name and it makes no difference.


If you split up the assignment like they do in the example at
http://msdn.microsoft.com/en-us/libr...umn.width.aspx

does it narrow it down?

Andrew


 
Reply With Quote
 
prodata
Guest
Posts: n/a
 
      16th Apr 2010
Sorry but no - still gives the same error.

But I've tried a slightly different tack of setting the .MinimumWidth
property rather than .Width (which should still do what I need to do).

If I set the .MinimumWidth = 100 ' (px)

then all runs fine. But if I set:

..MinimumWidth = 120

then the NRE exception gets thrown!

Bizarre! (But I'm having to use VB2005 currently and so this
(presumed) bug was maybe fixed in VB2008/2010?)
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Server Error: 451, Socket Error: 10053, Error Number: 0x800CCC0F =?Utf-8?B?RGFuaWVsYQ==?= Windows XP Help 3 17th Aug 2007 05:10 PM
Access error 3197 and JETCOMP.exe error "Error compacting database =?Utf-8?B?Vmlja3k=?= Microsoft Access 2 21st Jul 2007 12:29 AM
How I detect when a checkbox change a value in a dategridview (CheckedChanged) Paul Microsoft C# .NET 0 9th Aug 2006 11:24 AM
Error connecting to SQLExpress 2005 locally (error: 26 - Error Locating Server/Instance Specified) hfk0 Microsoft ASP .NET 2 27th Mar 2006 09:43 PM
3 Problems - Media Center Error, Date/Time Error, Downloading Updates Error angieangie Windows XP General 0 23rd Dec 2005 06:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:50 AM.