?
Solved

Revert changes back in Rowvalidating event of datagridview

Posted on 2010-08-20
5
Medium Priority
?
1,251 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
[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
  • 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

649 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