DataGrid on DataViewManager, no AllowNew?

W

Walt Borders

Hi,

I'm using a DataViewManager to sort the children of parent-child
nested tables in a DataSet. The DataViewManager and DataGrid work
very well doing every thing that is needed, except...

The DataGrid needs to:

AllowDelete = false;
AllowNew = false;
AllowEdit = false;

On the base tables in the dataSet, I set those values using
"DefaultView".

I'm also using DataGridTableStyle and setting the columns to "ReadOnly
= true".

Neither helps. Is there a better way to control the, AllowDelete,
AllowNew and AllowEdit for a dataGrid on a DataViewManager?

My environment: .NET, framework 1.1, C#, windows forms.

Thanks in advance
 
C

ClayB [Syncfusion]

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;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top