已经用了
dataGrid1.EndEdit(dataGrid1.TableStyles[0].GridColumnStyles[dataGrid1.CurrentCell.ColumnNumber], dataGrid1.CurrentRowIndex, false);
dataGrid1.BindingContext[dataGrid1.DataSource].EndCurrentEdit();
但还是不行,
这次只是新增的时候出问题,不新增只是编辑的时候没有问题.
最后一个新增的老是被丢掉,即使焦点移开也是一样.即使编辑过其他记录也是一样.
而不新增只是编辑的时候,焦点不移开也能保存.
哪位大侠知道怎么回事帮忙解决一下.
dataGrid1.EndEdit(dataGrid1.TableStyles[0].GridColumnStyles[dataGrid1.CurrentCell.ColumnNumber], dataGrid1.CurrentRowIndex, false);
dataGrid1.BindingContext[dataGrid1.DataSource].EndCurrentEdit();
但还是不行,
这次只是新增的时候出问题,不新增只是编辑的时候没有问题.
最后一个新增的老是被丢掉,即使焦点移开也是一样.即使编辑过其他记录也是一样.
而不新增只是编辑的时候,焦点不移开也能保存.
哪位大侠知道怎么回事帮忙解决一下.
DataView dv = dt1.DefaultView;
dv.AllowNew = true;
dataGrid1.DataSource = dv;
dt1.DefaultView.AddNew();
dt1.DefaultView.AllowNew=false;
DataRowView drv = dt1.DefaultView.AddNew();
//Change value here
drv.EndEdit();
dt1.DefaultView.AllowNew=false;
this.BindingContext[dataGrid1.DataSource,dataGrid1.DataMember].EndCurrentEdit();
贴全一点新增:
dt1.DefaultView.AllowNew=true;
dt1.DefaultView.AddNew();
dt1.DefaultView.AllowNew=false;
dataGrid1[dataGrid1.CurrentCell.RowNumber,2]=treeView1.SelectedNode.Text;
保存:
dataGrid1.EndEdit(dataGrid1.TableStyles[0].GridColumnStyles[dataGrid1.CurrentCell.ColumnNumber], dataGrid1.CurrentRowIndex, false);
dataGrid1.BindingContext[dataGrid1.DataSource].EndCurrentEdit(); MyClass cls1=new MyClass(); DataTable dt=cls1.update(dt1.GetChanges(),"baseset"," and class1='" + treeView1.SelectedNode.Text + "'");
着这一句后你调用DATASET的ACCEPT()方法接受改变了吗???
问题还是一样
谁知道是怎么回事啊
高手快来
addnew后面加这样一句
dataGrid1[dt1.DefaultView.Count-1,0]=System.Guid.NewGuid();
结帐,散分。