?
Solved

DataBindingSource CancelEdit

Posted on 2009-06-29
2
Medium Priority
?
642 Views
Last Modified: 2012-06-27
Hello,

I have a form that has about 10 different controls (such as textboxes and comboboxes).  When the user attempts to BindingSource.MoveNext or BindingSource.MovePrevious, it checks to see if any changes were made and if so a MsgBox appears with "Yes", "No", or "Cancel".  When the user clicks "No" I call BindingSource.CancelEdit and DataSet.RejectChanges.  My problem comes when the user returns to the record and it still displays all the previous entered data (that was rejected).  How do I refresh that data, so it returns to the original values.

So for example:  The form loads and the first textbox contains "Value1".  I then change that to "Value2".  I move records, and when requested wether to save the data or not, i choose "No".  I then move back to the record I was just working on, but despite cancelling the edit and rejecting the changes the first textbox is still set to "Value2" - How do i set it so it's "Value1" instead?
Me.AdapterManager.UpdateAll(Me.DataSetManager)
Me.DataSetManager.RejectChanges()

Open in new window

0
Comment
Question by:Gunit2507
[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
2 Comments
 
LVL 12

Accepted Solution

by:
wht1986 earned 2000 total points
ID: 24742685
Well I ran a quick example, but I did not have this problem.  My form has a typed dataset, 4 textboxes, and a binding source (as shown in the picture).  The code below after prompting, rejects or accepts the changes and moves the CurrentPosition. Perhaps you can see something your code is missing from the example
Imports System.IO
Imports System.DirectoryServices
Imports System.Linq
Imports System.Data.Linq
Imports System.Management
 
Public Class Form1
 
    Private oldPosition As Integer = -1
 
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DataSet11.DataTable1.AddDataTable1Row("hello", "Bob", "Bobson")
        DataSet11.DataTable1.AddDataTable1Row("goodbye", "Michael", "Jackson")
        DataSet11.DataTable1.AddDataTable1Row("hail", "fellow", "adventurer")
        DataSet11.AcceptChanges()
    End Sub
 
 
    Private Sub BindingSource1_PositionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingSource1.PositionChanged
 
        If oldPosition > -1 Then
            If DataSet11.DataTable1.Rows(oldPosition).RowState = DataRowState.Modified Then
                If (MessageBox.Show(Me, "Accept?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No) Then
                    DataSet11.DataTable1.Rows(oldPosition).RejectChanges()
                    BindingSource1.Position = oldPosition
                    Return
                End If
            End If
            DataSet11.DataTable1.Rows(oldPosition).AcceptChanges()
        End If
 
        oldPosition = BindingSource1.Position
 
    End Sub
 
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        BindingSource1.MoveNext()
    End Sub
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        BindingSource1.MovePrevious()
    End Sub
End Class

Open in new window

Capture.JPG
0
 

Author Closing Comment

by:Gunit2507
ID: 31598211
After spending about an hour researching this "problem" and then finally giving up and asking experts exchange to only find out I wasn't calling my code because the button handle event was incorrect.  Thanks a lot!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

762 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