BindingSource.AddingNew事件可以给新增数据设置需要的值

private void tableBindingSource_AddingNew(object sender, AddingNewEventArgs e)
 {
             BindingSource bs = (BindingSource)sender;
            DataView view = (DataView)bs.List;
            DataRowView row = view.AddNew();
            row["id"] = Guid.NewGuid();
            if (bs.Count == 1)
            {
                bs.EndEdit();
            }
            bs.MoveLast();
            e.NewObject = row;
}
不过有个bug,当表为空的时候需要endedit一下下:{

posted on 2007-11-23 20:38  J-Pei  阅读(355)  评论(0编辑  收藏  举报

导航