DataBinded TextBox

Hi,

On a window form, I've  binded a textbox on a dataset. When I change the text of this textbox the dataset doesn't change.(I've tested with the HasChanged() method). Why
On the same form, if I bind a datagrid and I make changes in this datagrid, the HasChanged() method return true.

Can someone explain

(sorry for my english).



Answer this question

DataBinded TextBox

  • RakeshMishra

    thanks a lot!Big Smile
  • gbulfon

    When editing using a Grid or a TextBox, you are not making changes to a DataView rather than the DataSet.  The DataView has row based commit semantics.  When using a Grid, the Grid will auto-commit the row data when moving to a new row and this will update the DataSet. Changing the TextBox will not cause the TextBox to "commit" the value to the DataSet - it will only change the DataView.  To get the TextBox to commit the data, you can do one of several things:

    Note: I assume you are bound through a BindingSource.

    1) You can add a "Commit" button that calls BindingSource.EndEdit();
    2) You can add a "Validated" event to the TextBox and call BindingSource.EndEdit() in the Validated handler.  You'd have to do this for each TextBox.
    3) You can hook the BindingComplete event on the BindingSource and call BindingSource.EndEdit().  This will work for any TextBox (or other simple control) bound through the BindingSource.  The code for this will look something like this:


    private bool _endingEdit = false;

    private void customersBindingSource_BindingComplete(object sender, BindingCompleteEventArgs e)

    {

    if (!_endingEdit && (e.BindingCompleteState == BindingCompleteState.Success) && (e.BindingCompleteContext == BindingCompleteContext.DataSourceUpdate))

    {

    try

    {

    _endingEdit = true;

    this.customersBindingSource.EndEdit();

    }

    finally

    {

    _endingEdit = false;

    }

    }

    }


     



    Joe


  • Derrick Morin

    Hi, have the same problem, but the shown solution didn't work.


    I wanted to update my datatable using the bindingsource.endedit() method. Instead of updating the datatable the method saves the changes in the bindingsource. The dataset.haschanges() method returns "false". How can I update the datatable


  • DataBinded TextBox