By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,572 Members | 1,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,572 IT Pros & Developers. It's quick & easy.

Master-Detail datagrid[allownew = false]

P: n/a
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 ?
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
[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> bl
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 ?

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.