Link to home
Start Free TrialLog in
Avatar of bhlabelle
bhlabelleFlag for Afghanistan

asked on

Changing Values in a datagridview

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

ASKER CERTIFIED SOLUTION
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bhlabelle

ASKER

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!