none
After bindingsource.endedit() and tableadapter.update, the dataset datatable.hasversion does not show proposed. RRS feed

  • Question

  • I hope you agree with 'The only dumb question is the one that isn't asked'.

    Visual Studio 2008 - Visual Basic - SQL CE 3.5 - stand alone, desktop application.

    I have a windows form bound to a datatable in a dataset.  When I change data in a control I check the dataset.datatable.hasversion(datarowversion.proposed) = true to prompt the user to accept the changes.  If yes, I do the bindingsource.endedit and tableadapter.update methods and this all works great.

    However, when I advance to the next row (I'm showing one row at a time) and change data in a control, the dataset.datatable.hasversion(datarowversion.proposed) returns false.  I suspect it is because of the endedit() having already been executed.  I've tried to reset the binding and 'Fill' the datatable but it doesn't make a difference.  I've also spent a few hours searching MSDN and the forums.

    I understand about changing data in multiple rows and updating all changes together, but in this case I want to update each row immediately.

    Any comments or suggestions are welcome.

    Wednesday, June 24, 2009 11:38 PM

Answers

  • HasVersion(DataRowVersion.Proposed) will tell you whether or not EndEdit has been called.  To determine if the row has changes since the last Fill or Update, you will want to check its DataRowVersion property to see if it is not equal to DataRowVersion.Unchanged.

    So, the first thing I would try working checks of DataRowVersion into your code.

    > However, when I advance to the next row

    You don't say how you are advancing to the next row.  I want to bring up that if you are using BindingNavigator, you don't have too much control over the process.  BindingNavigator is too simplistic for all but the most limited applications.  Fortunately, it is easy to "make your own" BindingNavigator by throwing some buttons on a Toolstrip and having those buttons call the BindingSource.Move___ methods.  This will let you insert code prior to the Move operation.


    Wednesday, June 24, 2009 11:56 PM

All replies

  • HasVersion(DataRowVersion.Proposed) will tell you whether or not EndEdit has been called.  To determine if the row has changes since the last Fill or Update, you will want to check its DataRowVersion property to see if it is not equal to DataRowVersion.Unchanged.

    So, the first thing I would try working checks of DataRowVersion into your code.

    > However, when I advance to the next row

    You don't say how you are advancing to the next row.  I want to bring up that if you are using BindingNavigator, you don't have too much control over the process.  BindingNavigator is too simplistic for all but the most limited applications.  Fortunately, it is easy to "make your own" BindingNavigator by throwing some buttons on a Toolstrip and having those buttons call the BindingSource.Move___ methods.  This will let you insert code prior to the Move operation.


    Wednesday, June 24, 2009 11:56 PM
  • I have been using BindingNavigator to advance to the next row but will try your suggection.  Thanks and I will post whether it works or not - tomorrow, as it is getting late here.
    Thursday, June 25, 2009 12:01 AM
  • I tried this and the dataset.datatable.hsaversion(datarowversion.proposed) still returns false.  Here are the sequence of steps I followed using debug to check the values:

    1. Open the form; the datatable is filled in the form load event.
    2. Change the data in a control on the form.
    3. Click a button on the BindingNavigator to move to the next row.
    4. Hits the breakpoint at the BindingNavigator_ItemClicked event.
    5. Dataset.Datatable.HasVersion(DataRowVersion.Proposed) = True
        FYI. I do a Me.ProcessTabKey(True) to change the focus as the edit condition isn't recognized until the changed control loses focus,
               this is only necessary if one control is changed but I don't know that so it is always executed.
    6. Message displayed asking to save changes - selected yes.
    7. Me.Validate().
    8. BindingSource.EndEdit().
    9. TableAdapter.Update(DataSet.DataTable.Item(currentrowposition) - I also tried this with updating the datatable instead of just the table row.
    10. Hits the breakpoint at the BindingNavigator_MoveNext event.
    11. Dataset.Datatable.HasVersion(DataRowVersion.Proposed) = False
          (both the original BindingNavigator Move Next and my version)
    12. Change the data in a control for the next row.
    13. Click a button on the BindingNavigator to move to previous row.
    14. Hits the breakpoint at the BindingNavigator_ItemClicked event.
    15. Dataset.Datatable.HasVersion(DataRowVersion.Proposed) = False.
    16. Hits the breakpoint on the BindingNavigator_MovePrevious event.
    17. Dataset.Datatable.HasVersion(DataRowVersion.Proposed) = False.

    According to the documentation a BindingSource.BeginEdit() is implicit when a bound control is edited but this doesn't seem to be happening
    after executing the EndEdit().

    I tried repeating the tableadapter Fill() method the same as in the form load event but no change.

    Also tried the BindingSource.ResetBindings but this didn't work either.


    Thursday, June 25, 2009 4:15 PM
  • It appears to be working.  I'm not 100% convinced yet because it has worked ocassionally in the past so I will do more extensive testing.

    The problem is I don't know why it's working now, but I will try to determine what I did that broke and/or fixed the issue.
    Tuesday, June 30, 2009 4:52 PM