locked
DataTable Bound to DatagridView DataRowState.Modified not getting change on first row RRS feed

  • Question

  • Updating the first record listed in my DataGridView that is bound to my DataTable . When I run Save process I run through this line of code to get all records that have been modified:

    DataTable
     modifiedRows 
    =
     unitDataDT
    .
    GetChanges
    (
    DataRowState
    .
    Modified
    );
    

    If I have changed the first record in my DataGridView my modifiedRows DataTable is Null. If I change any of the following records they are in my modifiedRows DataTable .
    I have tried changing other records in my DataGridView first and then changing the first record then running the Save process and still....other records are there and the first record is not.....

    Also....I checked the unitDataDT and it has the change. I sorted the datagridview to try and update a different record and it still did not add the change to the modifiedRows Datatable....so it seems to not work for the first record listed in the DataGridView.

    Any ideas?

    Tuesday, October 19, 2010 2:19 AM

Answers

  • Hi Kira,

    Found my issue...not sure why it just affected the first record that was displayed....but here it is....

     

    I added:

    this.BindingContext[unitDataDT].EndCurrentEdit();

    then check for modified Rows.

     

    Thanks!

     


    lengjr
    • Marked as answer by Lengjr Tuesday, October 19, 2010 1:49 PM
    Tuesday, October 19, 2010 1:49 PM

All replies

  • Hi Lengjr,

     

    Do you mean other rows work fine except the first row? Could you please check the RowState of the first row after you made some changes to it?

     

    unitDataDT.Rows[0].RowState

     

    Notice, after you made some changes to the row, please let the row lost focus. That cause the modified data submit to the DataTable.

     

    Sincerely,

    Kira Qian

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    Tuesday, October 19, 2010 6:11 AM
  • Hi Kira,

    Yes...I do mean the other rows work fine except the first row on the DataGridView.  When I check the unitDataDT.Rows[0].RowState it is "Unchanged" but if I also look at the unitDataDT.Rows[0]["fieldname"] it has my change in it.  So the DataTable is getting updated but the RowState is not.


    lengjr
    Tuesday, October 19, 2010 10:27 AM
  • Hi Kira,

    Found my issue...not sure why it just affected the first record that was displayed....but here it is....

     

    I added:

    this.BindingContext[unitDataDT].EndCurrentEdit();

    then check for modified Rows.

     

    Thanks!

     


    lengjr
    • Marked as answer by Lengjr Tuesday, October 19, 2010 1:49 PM
    Tuesday, October 19, 2010 1:49 PM