开发者

Insert a Row with a sorted DataGridView

My DataGridView is bound to the same BindingSource as the Insert Form, and the Name co开发者_如何学Clumn 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);
        }


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


    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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜