How To Cancel Edits on a control?

C

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
 
D

dpieski

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
 
D

dpieski

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
 
C

Crazy Cat

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,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top