473,414 Members | 1,697 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

NullReferenceException error in Datagrid

Hi,

I am assigning an array to a Datagrid and then formatting it using the
following code:

Dim cs As DataGridTextBoxColumn = New DataGridTextBoxColumn
cs.MappingName = "TestID"
cs.HeaderText = "Test ID"
cs.Alignment = HorizontalAlignment.Center
cs.Width = 50
ts.GridColumnStyles.Add(cs)

cs = New DataGridTextBoxColumn
cs.MappingName = "TestName"
cs.HeaderText = "Test Name"
cs.Alignment = HorizontalAlignment.Left
cs.Width = 75
ts.GridColumnStyles.Add(cs)

Dim cs2 As DataGridBoolColumn = New DataGridBoolColumn
cs2.MappingName = "Selected"
cs2.HeaderText = "Test Bool"
cs2.Width = 75
cs2.TrueValue = "true"
cs2.FalseValue = "false"
ts.GridColumnStyles.Add(cs2)

dgTest.TableStyles.Add(ts)

The first two formatings are fine it is just when I try and format a column
as a DataGridBoolColumn then I get the following error:

"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."
Would anyone have any ideas on how I could sort this out?

Any help/advice much appreciated.

Thanks in advance,
J
Nov 21 '05 #1
3 1276
Hi,

I dont see the problem here. Please Post some more code.

Ken
---------------------
"JenC" <Je**@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
Hi,

I am assigning an array to a Datagrid and then formatting it using the
following code:

Dim cs As DataGridTextBoxColumn = New DataGridTextBoxColumn
cs.MappingName = "TestID"
cs.HeaderText = "Test ID"
cs.Alignment = HorizontalAlignment.Center
cs.Width = 50
ts.GridColumnStyles.Add(cs)

cs = New DataGridTextBoxColumn
cs.MappingName = "TestName"
cs.HeaderText = "Test Name"
cs.Alignment = HorizontalAlignment.Left
cs.Width = 75
ts.GridColumnStyles.Add(cs)

Dim cs2 As DataGridBoolColumn = New DataGridBoolColumn
cs2.MappingName = "Selected"
cs2.HeaderText = "Test Bool"
cs2.Width = 75
cs2.TrueValue = "true"
cs2.FalseValue = "false"
ts.GridColumnStyles.Add(cs2)

dgTest.TableStyles.Add(ts)

The first two formatings are fine it is just when I try and format a
column
as a DataGridBoolColumn then I get the following error:

"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."
Would anyone have any ideas on how I could sort this out?

Any help/advice much appreciated.

Thanks in advance,
J

Nov 21 '05 #2
Hi Jen,

A stab in the dark here! Is it possible that the Boolean values are looking
for 1 & 0 instead of the strings "True" & "False"??

Rgds, Phil

"JenC" <Je**@discussions.microsoft.com> wrote in message
news:95**********************************@microsof t.com...
Hi,

I am assigning an array to a Datagrid and then formatting it using the
following code:

Dim cs As DataGridTextBoxColumn = New DataGridTextBoxColumn
cs.MappingName = "TestID"
cs.HeaderText = "Test ID"
cs.Alignment = HorizontalAlignment.Center
cs.Width = 50
ts.GridColumnStyles.Add(cs)

cs = New DataGridTextBoxColumn
cs.MappingName = "TestName"
cs.HeaderText = "Test Name"
cs.Alignment = HorizontalAlignment.Left
cs.Width = 75
ts.GridColumnStyles.Add(cs)

Dim cs2 As DataGridBoolColumn = New DataGridBoolColumn
cs2.MappingName = "Selected"
cs2.HeaderText = "Test Bool"
cs2.Width = 75
cs2.TrueValue = "true"
cs2.FalseValue = "false"
ts.GridColumnStyles.Add(cs2)

dgTest.TableStyles.Add(ts)

The first two formatings are fine it is just when I try and format a
column
as a DataGridBoolColumn then I get the following error:

"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."
Would anyone have any ideas on how I could sort this out?

Any help/advice much appreciated.

Thanks in advance,
J

Nov 21 '05 #3
JenC,

cs2.TrueValue = "true"
cs2.FalseValue = "false"

http://msdn.microsoft.com/library/de...valuetopic.asp

true en false

I hope this helps,

Cor
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
0
by: sarah | last post by:
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...
2
by: Shannon | last post by:
I am having a very strange issue with my asp.net application. I have created a datagrid which dynamically gets populated from a person choosing a value from a dropdown list and entering a quantity...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
3
by: Ryan Liu | last post by:
Hi there, I got a NullReferenceException when delete last row in a datagrid. I had hard time to solve since it does not occur in my own code. I put a datagrid in my inherited user control,...
3
by: postings | last post by:
Hi Can anybody help? (ASP.NET 1.1) The event below is triggered when the user clicks an update button column. I am trying to update a dataset which eventually gets bound with a datagrid,...
2
by: sxiao | last post by:
Hi, there I got a NullReferenceException when there are more than one users trying to open the same page at the same time. The senerio is: Two users logged into the web application using the...
3
by: mahtan | last post by:
Please help I have the problem that when I change the data in a Windows.Forms.DataGrid by a separate thread the following Exception is thrown: ThreadSystem.NullReferenceException in...
3
by: roopsd | last post by:
I am using VS.NET 2003 with crystal reports XI release 2. I get a runtime error at the following line: oRptForm.crystalReportViewer.ReportSource = oReport An unhandled exception of type...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.