[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Changing Values in a datagridview

Posted on 2011-03-11
2
Medium Priority
?
508 Views
Last Modified: 2012-05-11
I had asked how to check to see if a cell in a datagridview was changed so I could prompt the user if they wanted to save the changes.  The solution was to set the value of a global variable "CellBegin" (which I store as a string) with the cell contents on the begin edit and then compare it on the cell end edit.  It works very nicely for existing rows in the data.  However, as soon as I begin to enter a new record I get the following error message:

Conversion from type 'DBNull' to type 'String' is not valid.

Should I change the variable to something other than a string (variant?).  Or is there a way to recognize this entry is a new record and then bypass the compare?  Hope I'm making sense.
Private Sub DataGridView1_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DataGridView1.CellBeginEdit
        CellBegin = Me.DataGridView1.CurrentCell.Value
    End Sub

Open in new window

0
Comment
Question by:bhlabelle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Accepted Solution

by:
nepaluz earned 2000 total points
ID: 35110783
just encapsulate the statement in a try catch and set the CellBegin value to nothing, e.g

Private Sub DataGridView1_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles DataGridView1.CellBeginEdit
   Try
        CellBegin = Me.DataGridView1.CurrentCell.Value
   Catch ex As Exception
        CellBegin = Nothing
   End Try
End Sub
0
 

Author Closing Comment

by:bhlabelle
ID: 35110895
I don't know why, but I always forget to do things in a try catch.  Thank goodness I'm not a real programmer.

Thanks for the help!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question