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一下下:{
{
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一下下:{
一蓑烟雨任平生