Windows DataGrid Child Tables New row Hide

  • Thread starter Thread starter Sonia Igla
  • Start date Start date
S

Sonia Igla

Hi,
I use DataGrid.DataSource = dataview that it table is parent table
In dataset with relationships.
dataview.AllowNew = false hides last * row in datagrid parent.
But for child grids the last new row is visible.
The childDataTable.DefaultDataView.AllowNew = false don't help.
How can it be solved?
Thanks Sonia.
 
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;
}
}
 
Back
Top