Solved

Revert changes back in Rowvalidating event of datagridview

Posted on 2010-08-20
5
1,216 Views
Last Modified: 2013-11-27
Hi Experts,
I  am using visual studio 2005 and working on Win forms application. I have a datagridview. I prompt the user to save if the data has changed in rowValidating event.
If the user says "yes", everything is fine. But if users says "no", then I manage not to save the data., but I visually also want to remove the changes. how do i revert back the changes? Attached is my code. Any help will be greatly appreciated

Private Sub DataGridView1_RowValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.RowValidated

        Dim lResponse As Long

        If UpdatePending Then

            lResponse = MessageBox.Show("Do you wish to save changes?", "Data has Changed", MessageBoxButtons.YesNo)

            If lResponse = vbYes Then

                Try

                    Dim command_builder As SqlCommandBuilder

                    command_builder = New SqlCommandBuilder(daHotel)

                    Me.daHotel.Update(dsHotel.Tables(0))

                    DataGridView1.Refresh()

                    Me.UpdatePending = False

                Catch ex As Exception

                    MessageBox.Show(ex.Message)

                End Try

            Else

                DataGridView1.Refresh()

                Me.UpdatePending = False

            End If

        Else

            Me.UpdatePending = False

        End If

    End Sub

Open in new window

0
Comment
Question by:RekhaShah
  • 3
5 Comments
 
LVL 9

Expert Comment

by:puru1981
ID: 33490696
for this you need to handle CancelRowEdit event.

visit the link below

http://msdn.microsoft.com/en-us/library/15a31akc.aspx
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33490721
hi..
Just use Me.DatagridView.CancelEdit in your Else Condition
0
 
LVL 18

Accepted Solution

by:
John (Yiannis) Toutountzoglou earned 500 total points
ID: 33490753
also When you are using a dataset ..you can Set .....MyDataset.RejectChanges
0
 
LVL 18

Expert Comment

by:John (Yiannis) Toutountzoglou
ID: 33490790
try
Dim dt As DataTable = TryCast(Me.dataGridView1.DataSource, DataTable)
dt.RejectChanges()
0
 

Author Closing Comment

by:RekhaShah
ID: 33497880
Thank  you. It worked.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now