473,406 Members | 2,619 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,406 software developers and data experts.

Test to see if datagridview cell is null

Before saving information in a datagridview to a database I'm trying to
verify tha certain cells are not blank (dbNull). When I run this code:

If IsDBNull(Me.dgvHistory(2, Me.dgvHistory.CurrentCell.RowIndex).Value)
Then
Me.dgvHistory(2, Me.dgvHistory.CurrentCell.RowIndex).Value =
Nothing
End If

This error apears when the first line is executed:
System.NullReferenceException
{"Object reference not set to an instance of an object."}

I've spent a few hours work on this, but nothis seems to work. Any
suggestions would be greatly appreciated.
--
Tony
Nov 8 '07 #1
2 8706
Something in that statement has a value of Nothing. The first thing
to do is to use the debugger to see what has the null reference. You
can't fix it without knowing what is wrong.

When you get the error, what is the value of:
Me.dgvHistory.CurrentCell
Me.dgvHistory.CurrentCell.RowIndex
Me.dgvHistory(2, Me.dgvHistory.CurrentCell.RowIndex)

Most likely CurrentCell is Nothing.

On Thu, 8 Nov 2007 11:18:06 -0800, Tony A.
<To***@discussions.microsoft.comwrote:
>Before saving information in a datagridview to a database I'm trying to
verify tha certain cells are not blank (dbNull). When I run this code:

If IsDBNull(Me.dgvHistory(2, Me.dgvHistory.CurrentCell.RowIndex).Value)
Then
Me.dgvHistory(2, Me.dgvHistory.CurrentCell.RowIndex).Value =
Nothing
End If

This error apears when the first line is executed:
System.NullReferenceException
{"Object reference not set to an instance of an object."}

I've spent a few hours work on this, but nothis seems to work. Any
suggestions would be greatly appreciated.
Nov 8 '07 #2
I use
If DataGridView1.Item(e.ColumnIndex, e.RowIndex).Value.ToString.Length
= 0 Then ...

It seems to work.

Dec 12 '07 #3

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

Similar topics

0
by: Steve | last post by:
I am looking for an example of a custom user control ( 2 labels and 2 datetime pickers ) in a datagridview cell. Every example I have come across handles only once control such as a datetimepicker...
11
by: dgk | last post by:
Is there a way to change the foreground or background color of a single cell in an unbound datagridview?
3
by: Rich | last post by:
Hello, If I want to update data displayed in a datagrideview/datagridview cell, how can I determine what cell I am updating? I am looking at the click event below, for example. Can I get...
10
by: steve | last post by:
Hi All I would like to be able to change the cell borders on certain cells to none at runtime to make a group of cells appear to be merged I have tried the following in the cellformatting...
2
by: galletg | last post by:
please; how to write by code in a datagrid view cell a text in a textbox. thank you for your help. georges gallet
12
by: cj | last post by:
When viewing a datatable in a datagridview one of the columns in it is a "note" field which can be quite long. I would like to have the note field of the currently selected row of the datagrid...
0
by: varunk2 | last post by:
Hi How to autocomplete a datagridview cell in c# windows forms. Please anybody help me... Thanks in advance Regards,
0
by: hydro123 | last post by:
I am using VC++2008 and am trying to read data enetered in unbound datagridview to implement in function. Under button_click event I entered the following: // initialize varaibles from...
0
by: ziketo | last post by:
Hi, I searched a lot about changing the DataGridView cell borders. BYTES helped me so I will write down the solution: 1. You should override the class DataGridViewTextBoxCell, and the new class...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...

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.