BindingSource.CancelEdit problem

king_jeremy

Member
Joined
Oct 20, 2009
Messages
13
Programming Experience
Beginner
Hi,
I have a detailsView on tabPage1. When a user leaves tabPage1 without saving his changes the TabControl.Selecting event checks for any changes being made if it detects any a yesNo dialog opens and asks user if he wants to submit the changes or not before navigating the other tabPage. My problem is I cannot detect the changes being made without calling the bindingSource.EndEdit method but once I call it BindingSource.CancelEdit does not cancels the changes anymore. I guess this is the natural behavior of the bindingSource but then how am I supposed to check for any changes without calling an endEdit method and if decided use the cancelEdit method?
 
I think you're mistaken. DetailsView is a web control, for ASP.NET apps. You can't possibly have one on a Windows Form. Maybe you mean a DataGridView or something else.

What is your BindingSource bound to? Is it a DataTable? If so then the Current property of the BindingSource returns a DataRowView. I think you'll find that its RowVersion property will have the value Proposed if there are uncommitted changes in the row.
 
The bindingSource is bound to a dataset and it is not a dataGridView it is the details of a table (which is not important either case it is the bindingSource we are trying to check).
Well the solution is as you suggested, I wrote a function checking the RowVersion property something like below
VB.NET:
   Private Function ValidateBindingSource() As Boolean
        Dim rv As DataRowView = CType(Me.MyBindingSource.Current, DataRowView)
        Dim row As DataRow
        For Each rowView As DataRowView In MyBindingSource
            row = rowView.Row
            If row.HasVersion(DataRowVersion.Proposed) = True Then
                If row.HasVersion(DataRowVersion.Current) = True Then
                    'Modified Record
                    Return True
                Else
                    'New Record
                    Return True
                End If
            ElseIf row.Item("Name", DataRowVersion.Current) <> _
             row.Item("Name", DataRowVersion.Original) Then
                'Modified Record
                Return True
            End If
        Next
        'nothing has changed
        Return False
    End Function
Thanks anyway.
 
Back
Top