周克的技术Blog

在.Net的海洋里面寻找真我

My Links

Blog Stats

News

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 2006-06-06 03:57 周克 阅读(...) 评论(...) 编辑 收藏