[I found the solution from other newsgroup]
I think you can subscribe to the DataGrid's Navigate event, get the
CurrencyManager there, and set the AllowNew property of the
CurrencyManager's List at that point. Below is some code.
=============
Clay Burch, .NET MVP
Visit
www.syncfusion.com for the coolest tools
private void Form1_Load(object sender, System.EventArgs e)
{
DataTable parentTable = GetParentTable();
DataTable childTable = GetChildTable();
DataSet ds = new DataSet();
ds.Tables.AddRange(new DataTable[]{parentTable, childTable});
DataRelation parentToChild = new DataRelation("ParentToChild",
parentTable.Columns["parentID"], childTable.Columns["ParentID"]);
ds.Relations.AddRange(new DataRelation[]{parentToChild});
this.dataGrid1.DataSource = parentTable.DefaultView;
parentTable.DefaultView.AllowNew = false;
this.dataGrid1.Navigate += new
NavigateEventHandler(dataGrid1_Navigate);
}
private void dataGrid1_Navigate(object sender, NavigateEventArgs e)
{
if(e.Forward)
{
CurrencyManager cm =
(CurrencyManager)this.dataGrid1.BindingContext[this.dataGrid1.DataSource,
this.dataGrid1.DataMember];
((DataView)cm.List).AllowNew = false;
}
}
----------------------------------------
"Agnes" <ag***@dynamictech.com.hk> ¦b¶l¥ó
news:%2***************@tk2msftngp13.phx.gbl ¤¤¼¶¼g...
In my one datagrid, there is master - detail relationship.
I can set dv.allownew = false, However, as the user click into detail, it
can't set to allownew = false.
Does anyone know how to solve it ?