简体   繁体   中英

ADGV C# DataGridView - update query bug?

I'm trying to use auto-generated advancedDataGrid - ADGV ( adgv.codeplex.com ).

Problem is that the below shown procedure does not succeed with updating the SQL table every time... It is exactly every second Event raised...

private void advancedDataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
    {
        int rowIdx = advancedDataGridView1.CurrentCell.RowIndex;
        DataRowView drv = (DataRowView)advancedDataGridView1.Rows[rowIdx].DataBoundItem;
        DataRow dr = drv.Row;
        this.levTableAdapter.Update(dr); //strange, but Update is done every second time....
    }

How to debug it?, if I add another line of this.levTableAdapter.Update(dr) - it will not help either...

EDIT: Looked into behaviour again and I have to update:

1st enter "A" - noChangeSQL, Event picks "A", "A" in the datagrid cell.
2nd enter "B" -  "A" in SQL, Event picks "A", "A" in cell.
3rd enter "C" -  "A" in SQL, Event picks "C", "C" in cell.
4rd enter "D" -  "C" in SQL, Event picks "C", "C" in cell.
5th enter "E" -  "C" in SQL, Event picks "E", "E" in cell.

Are you sure, it's every second event? Could it be it doesn't save just the last row you changed? If it is a timing issue or excecution order problem (like row state update happening after EndEdit event gets handled), you can defer it a bit, with Form's BeginInvoke, like this:

private void advancedDataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
    int rowIdx = advancedDataGridView1.CurrentCell.RowIndex;
    DataRowView drv = (DataRowView)advancedDataGridView1.Rows[rowIdx].DataBoundItem;
    DataRow dr = drv.Row;
    BeginInvoke((Action)(() => SaveRowChanges(dr)));
}

private void SaveRowChanges(DataRow dr)
{
    DataRow[] rows = { dr };
    adapter.Update(rows);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM