views:

243

answers:

1

I have a DataViewGrid I populated from a DataTable in a query to a DB. While trying to capture the Row_Leave event, so I could properly update it, I can't seem to capture the latest value in boolean columns.

If I update just a text field, when I access the underlying DataSource I get the latest value I entered, buy if I access the boolean, I get the previous value.

I am accessing the Rows like this:

if (allCorrect)
{
    if (((DataRowView)dgView.Rows[e.RowIndex].DataBoundItem).IsNew)
    {                        
       this.InsertEntry((DataRow)((DataRowView)dgView.Rows[e.RowIndex].DataBoundItem).Row);
    }
    else
    {                        
        this.UpdateEntry((DataRow)((DataRowView)dgView.Rows[e.RowIndex].DataBoundItem).Row);
    }
 }

(quite convoluted way to access the underlying row, but works just like accessing the DataSource of the DGV, so it is not the problem.)

Any ideas?

EDIT: I've narrowed the issue to proper event calling. It seems that RowLeave gets called before EndCellEdit and even CellValueChanged. Therefore, the row never gets the status update (to be updated in the DB) and doesn't do it. Can I change the order of these events (as to work properly)? I found out this is a known issue that was supposed to change in Orcas, but they never did.

+1  A: 

Ok, got a workaround it.

After checking that it needs to be updated with:

        if(!(dgView.IsCurrentCellDirty))
        {
            return;
        }

I do a CommitEdit to apply the changes of the cell (of which event has not happend yet due to the aforementioned bug) with

        dgView.CommitEdit(0);

and when the the updated/insert happens, the row will get the latest values.

Manuel Ferreria