[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Revert changes back in Rowvalidating event of datagridview

Posted on 2010-08-20
5
Medium Priority
?
1,259 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 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
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…
Suggested Courses

872 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