views:

236

answers:

2

My DataGridView is bound to the same BindingSource as the Insert Form, and the Name column is sorted. After insert is done, the groupBindingSource.Current is not returning the new inserted DataRowView but the last row in the sort order what makes the Update do nothing.

        FormGroup formGroup = new FormGroup();
        formGroup .Source = groupBindingSource;
        formGroup .setMode(FormGroup.Mode.Insert);
        if (formGroup .ShowDialog() == DialogResult.OK)
        {
            DataRowView drv = (DataRowView)groupBindingSource.Current;
            grupoTableAdapter.Update(drv.Row);
        }
A: 

Can you disable sorting before insert and enable it after?

something like this:

//...
//disable sorting
if (formGroup .ShowDialog() == DialogResult.OK)
{
    DataRowView drv = (DataRowView)groupBindingSource.Current;
    grupoTableAdapter.Update(drv.Row);
}
//enable sorting
najmeddine
A: 
    DataRowView drv = (DataRowView)source.AddNew();
    grupoTableAdapter.Update(drv.Row);
    grupoBindingSource.Position = grupoBindingSource.Find("ID", drv.Row.ItemArray[0]);

it makes the DataGridView that is bound to select the new added row accordingly even if any column is sorted out.

Ruben Trancoso