Home All Groups Group Topic Archive Search About

How To Cancel Edits on a control?

Author
15 Mar 2006 7:32 PM
Crazy Cat
Using Visual Basic 2005 how do I cancel edits on a databound control. I
want the user to be able to cancel all edits on a form. My main
databound control is a DataGridView which is bound to a BindingSource,
which in turn is bound to a SQL Server data source. I tried
ResetBindings, but nothing appears to happen visually, and the
bindingsource's HasChanges method indicates that changes have been made
even after I attempt to use it.

Thanks,
Crazy

Author
15 Mar 2006 10:14 PM
dpieski@gmail.com
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuExit.Click
        Dim changes As DataSet = DsProduct1.GetChanges()
        Dim answer As DialogResult
        If Not changes Is Nothing Then
            answer = MessageBox.Show("Save data changes?", "Save",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
            If answer = DialogResult.Yes Then
                Dim count As Integer = dbProduct.Update(changes)
                MessageBox.Show("Database updated " & count & " rows
successfully")
                DsProduct1.AcceptChanges()
            End If
        End If
        Me.Close()
    End Sub
Author
15 Mar 2006 10:15 PM
dpieski@gmail.com
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles mnuExit.Click
        Dim changes As DataSet = DsProduct1.GetChanges()
        Dim answer As DialogResult
        If Not changes Is Nothing Then
            answer = MessageBox.Show("Save data changes?", "Save",
MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
            If answer = DialogResult.Yes Then
                Dim count As Integer = dbProduct.Update(changes)
                MessageBox.Show("Database updated " & count & " rows
successfully")
                DsProduct1.AcceptChanges()
            End If
        End If
        Me.Close()
    End Sub
Author
16 Mar 2006 3:13 PM
Crazy Cat
dpie***@gmail.com wrote:
Show quoteHide quote
> Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles mnuExit.Click
>         Dim changes As DataSet = DsProduct1.GetChanges()
>         Dim answer As DialogResult
>         If Not changes Is Nothing Then
>             answer = MessageBox.Show("Save data changes?", "Save",
> MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
>             If answer = DialogResult.Yes Then
>                 Dim count As Integer = dbProduct.Update(changes)
>                 MessageBox.Show("Database updated " & count & " rows
> successfully")
>                 DsProduct1.AcceptChanges()
>             End If
>         End If
>         Me.Close()
>     End Sub

Thanks,

I actually ended up using RejectChanges which seems to work fine in
conjunction
with HasChanges.

Thanks again,