Confirm ... is it a bug?

I'm using a datagrid in vb.net in an windows application.

If I make a change in the datagrid, in one column only, then click on a button to update the database, the app does not recognise that a change has been made (ie. dataset.GetChanges returns nothing). The pencil icon still appears next to the row that was changed.

If I manually click on another row in the datagrid, calling dataset.GetChanges will return one row as expected.

How can I force the change to be recognised without having to manually click off the changed row

Thanks!!



Answer this question

Confirm ... is it a bug?

  • Karl S

    The funny thing is that I'm not seeing this behavior. With a DataGrid bound to a DataSet, no matter what I do. Maybe it's because I'm using VS.NET 2003, but moving to another column, or clicking a button both cause the pencil icon to go away, and the DataSet tells me that is has changes. Nope, just tried it in VS.NET 2002, and get the same behavior.

    In any case, you're getting different behavior and I'm not sure why. So let's talk about what you're seeing...

    This isn't really a datagrid issue, but a fact of the way the underlying CurrencyManager object is working. DataSet.GetChanges (or DataSet.HasChanges) won't return True for a row until you've either left the row, or called the CurrencyManager.EndCurrentEdit method. (Clearly, the DataGrid is taking care of this for me, but not for you. Don't know why.)

    If you want to be able to save changes while changing only a single column and then clicking a button, you'll need to make sure to update the CurrencyManager first, using code like this:
    DirectCast(Me.DataGrid1.BindingContext(DataSet11), CurrencyManager).EndCurrentEdit()
    Replace the DataGrid name, and the DataSet name, with your own information. Again, I'm not sure why you're needing this and I'm not, but ending the current edit using this method should allow you to see the changes when you click your button.


  • gdumazet

    I confirm the behavior posted by Ken.

    I have a complex form that show a record from more tables of a database.
    Controls are distribuited within more tabs, panels and groupboxes.
    All user controls are managed with BindingContext and all works good if, after changes made in the user controls, I set focus on a Button or other control.

    Please note that I also try to set focus on another control from code, just before executing the database update function, but also in this case there's no success and database is not updated.

  • Confirm ... is it a bug?