How to call stored proc from a change to a date in datagridview

DeepBlueZen used Ask the Experts™
Ok, here's a bit of an odd situation.  I have a datagridview which contains all sorts of information relating to investment bonds. When a bond is intiially created, I populate a table with the bond ID and the dates on which it'll pay interest.  so far so good.

In my datagridview, I want the user to be able to correct errors made when the bond was first input. If they change the interest payment frequency or maturity date, I want to fire two stored procs. one which deletes the entries for the interest payment dates and the other to recreate these entries with the correct data.  both these stored procedures work just fine.

The problem is a) how do i detect that a specified field in the datagridview has changed and b) how do I retrieve the new value the user has entered into the datagridview. (I'll need to pass the new values into my stored procs as input parameters)

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Are you using ASP.Net or WindowsForms?

You have CellValueChange event fired when the value of a cell changes.

Take a look to this:


I'm using windows forms.  

Really, I want to compare old value against new value on the save event of the binding navigator, so I guess what I need is how to access the original and new values.  I'm trying to avoid deleteing and creating data in a child table until the user actually commits the change. If he edits a value, and then edits it again and changes his mind one more time, rebuilding the interest date entries after every edit probably adds too much overhead.  I'd rather validate his (her) input on cell change, but not delete and recreate any interest date entires until they actually commit the change.

 Thanks for the link though
Then you can use CellValidating event
Private Sub DataGridView1_CellValidating(ByVal sender As Object, ByVal e
As System.Windows.Forms.DataGridViewCellValidatingEve ntArgs) Handles DataGridView1.CellValidating
Dim strOld As String = DataGridView1.Item(e.ColumnIndex, e.RowIndex).Value.ToString
Dim strNew As String = e.FormattedValue.ToString

Trace.WriteLine(String.Format("Old Value {0} {1}New Value {2}",
strOld, ControlChars.NewLine, strNew))
End Sub
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.


Hello CaptainHarlock

Great answer, but I'm trying to perform this check on the binding navigator save event, not at the cell validating event. Essentially, I don't want to call stored procedures against my underlying data until the user actually and finally commits the change by saving. It might still be possible to retreive the old and new values using your code fragment though. I'll give it a go and let you know how I get on.

When you initially populate the cell with data from the DB, save a copy of it. Then, when the user is prepared to commit, you can do a comparison and see if anything has changed.


Thank you.  That's essentially what I did.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial