473,545 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataGridView Problem with unbound Checkbox cell

Hi,

I'm having a problem with a datagridview control when trying to read
the value of an unbound checkbox cell.

The code below works fine if I click on any text cell, bound or unbound,
and also if I click on a data bound checkbox cell.

But it fails with null reference exception if I try to read the value on an
unbound cell.

Can anybody show me where I'm going wrong?

TIA

Martin.

Private Sub InvoicesDataGri dView_CellClick (ByVal sender As Object, _
ByVal e As System.Windows. Forms.DataGridV iewCellEventArg s) _
Handles InvoicesDataGri dView.CellClick
' This line works, prints system.boolean
Debug.Print( _
Me.GridView.Row s(e.RowIndex).C ells(e.ColumnIn dex).ValueType. ToString)

' This line fails, NullReferenceEx ception
Debug.Print( _
Me.GridView.Row s(e.RowIndex).C ells(e.ColumnIn dex).Value.ToSt ring)

End Sub
Dec 3 '06 #1
1 3500
Resolved...

I didn't realise I had to call CommitEdit on the DataGrid before
trying to read the checkbox value.

"Martin" <@ntlworld.comw rote in message
news:%2******** *******@TK2MSFT NGP06.phx.gbl.. .
Hi,

I'm having a problem with a datagridview control when trying to read
the value of an unbound checkbox cell.

The code below works fine if I click on any text cell, bound or unbound,
and also if I click on a data bound checkbox cell.

But it fails with null reference exception if I try to read the value on
an
unbound cell.

Can anybody show me where I'm going wrong?

TIA

Martin.

Private Sub InvoicesDataGri dView_CellClick (ByVal sender As Object, _
ByVal e As System.Windows. Forms.DataGridV iewCellEventArg s) _
Handles InvoicesDataGri dView.CellClick
' This line works, prints system.boolean
Debug.Print( _
Me.GridView.Row s(e.RowIndex).C ells(e.ColumnIn dex).ValueType. ToString)

' This line fails, NullReferenceEx ception
Debug.Print( _
Me.GridView.Row s(e.RowIndex).C ells(e.ColumnIn dex).Value.ToSt ring)

End Sub

Dec 3 '06 #2

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

Similar topics

8
9222
by: Mike | last post by:
Hi all, I have a DataGridViewCheckBoxColumn as one of my columns in a DataGridView. I want this checkbox to only be checked, but not unchecked - it's used by the user to audit that they have "seen" and checked an order. In VB6 I would handle the Mouse Button Down event, test the target cell and set the mouse event arguements to nothing....
4
21276
by: Hexman | last post by:
Hello All, I'd like to find out the best way to add a cb column to a dgv and process efficiently. I see at least two ways of doing it. ------------------------------- 1) Add a cb to the dgv, iterate thru the dgv and update the bound fields if the cb has been checked. Then do the update and accept changes. How do I access the cb and its...
1
7423
by: sklett | last post by:
I've got a strange situation here. I have a databound DataGridView that also has un-bound columns. When the view loads, I want to update the values of the unbound columns. If I attempt to modify the unbound column's cells in the OnLoad() handler the results are very strange. If I add a button to my view and update the unbound cells in the...
2
4273
by: mrstrong | last post by:
Gday, I have a datagridview that I am creating the columns programatically which all seems to work fine. I have a couple of dropdown boxes, so I have set the editMode= EditOnEnter. Now my checkboxes dont seem to work, and the datagridview throws a dataerror when I try to leave the cell after trying to check/uncheck the checkbox?!
2
6106
by: mrstrong | last post by:
Gday, Why would all my checkboxes inside a datagridview stop working (ie checked state not updating when user clicks) when the datagridview's editmode property is changed to "EditOnEnter"? It seems to return an error: "Formatted Value of the cell has wrong type". It works fine when the datagridview's editmode property is
1
13719
by: zacks | last post by:
Using VS 2005. I have an app that has a DataGridView control. This control has two columns, the first column is a standard TextBox, and the second column is a CheckBox. I am having difficulty determining the state of the CheckBox, whether it is checked or not. I have identified an event that fires when the user clicks in the checkbox,...
2
2137
by: =?Utf-8?B?S2lt?= | last post by:
foreach (DataGridViewRow row in this.dataGridView.Rows) { if (row.Cells.Value.ToString() == "true") { return true; } } return false;
4
2580
by: Benysh | last post by:
Hi everyone. I'm having a really annoying problem I can't solve and couldn't find an answer to anywhere, let's see if you got what it takes. I have a dataGridView on a C# Windows Form. Unbound. I fill in rows with a button. I have a checkbox column which isn't read-only (unlike the other columns) so the user could check whatever row he...
0
5638
by: priyamtheone | last post by:
I'm trying to make a datagridview column to act like a datetimepicker column (C#.Net 2005). These are the behaviours that the dgv should have: 1) Initially all the cells of the dtp column should be blank unless they are filled by the user. 2) As soon as the user enters a cell, the dtp control should appear as the editing control of that cell. If...
0
7484
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7675
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7928
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7440
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
5997
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3470
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3451
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1902
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
726
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.