Getting BindingContext to save current edits.

I have a form that uses BindingContext and CurrencyManager.

It works fine, but when I click save, the current TextBox does not save its information (maybe it's not marked as dirty until moving to a different Position ).

What's the simple, standard way of coding a statement that basically says "save the current record's updates too"


Answer this question

Getting BindingContext to save current edits.

  • odeddror

    Sweet. Thanks, man.
  • Phoenixfire1710

    You'll need to call EndCurrentEdit on the Form's BindingContext to flush the value out to your bound data object. For example call the following line of code before calling your db update method:

    Me.BindingContext(myDataSet.MyDataTable).EndCurrentEdit()

    HTH,

    -Paul


  • blond

    hmmm I am having a similar problem and Calling EndCurrentEdit works great when my users are polite and use the close button.  

    But when they click on the corner "X" ... 
    Calling the EndCurrentEdit  no longer appears to work.  I added an eventHandler to the form closing event.  It is being called and works if they do more than 1 edit and change focus.  

    But if they do only 1 edit then .hasChanges is false even after I call the .EndCurrentEdit and the getChanges is empty as well.

    protected void CreatureForm_Cancel (Object sender, CancelEventArgs e) 
    {
    EndCurrentEdits();
    System.Data.DataSet dataSetChanged;
    dataSetChanged = (dsCreature.GetChanges(DataRowState.Modified));
    if (dataSetChanged != null)
                            // or just using this as well
    //if(dsCreature.HasChanges(DataRowState.Modified))

    argh I guess I'll just tell them to be better behaved else changes are not saved.

  • lslmustang


    Hi Silona,

    It depends on your needs and the expected behavior when clicking the "X" on the form. You might want to tell your users that clicking the "X" is a fail-safe way to close your form and abort any changes that are made, for example. 

    If you want to save any changes when the "X" is clicked, you'll need to call your "EndCurrentEdits()" logic when the "X" is clicked, too, (in the Form_Closing event) in addition to when your "Save" button is clicked (you'll save the data if they haven't already via the Save button click--check HasChanges or a form variable).

    HTH,

    -Paul

  • Getting BindingContext to save current edits.