Prevent Add New row in grid

T

Tyke Czekalski

I need to allow edits to my data grid. If I have a single
table in my dataset, the following code works great.

CurrencyManager cm = (CurrencyManager)this.BindingContext
[this.grdPlates.DataSource,
this.grdPlates.DataMember];

((DataView)cm.List).AllowNew = false;


However, I have a scenario with mulitple data tables with
a relation between them. I call the above code on the
parent table which is set as the original data member
object, and it does prevent the row from displaying in the
parent table.

But when I navigate to the child table, the add new row
appears. I've tried several variations and events with no
luck turning off the add new row on this child table.

Anyone have any suggestions?

Tyke
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hi,

You should do the same thing:
CurrencyManager cm = (CurrencyManager)this.BindingContext
[this.grdPlates.DataSource,
this.grdPlates.DataMember];

((DataView)cm.List).AllowNew = false;

when the user navigates to the child table.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Tyke Czekalski said:
I need to allow edits to my data grid. If I have a single
table in my dataset, the following code works great.

CurrencyManager cm = (CurrencyManager)this.BindingContext
[this.grdPlates.DataSource,
this.grdPlates.DataMember];

((DataView)cm.List).AllowNew = false;


However, I have a scenario with mulitple data tables with
a relation between them. I call the above code on the
parent table which is set as the original data member
object, and it does prevent the row from displaying in the
parent table.

But when I navigate to the child table, the add new row
appears. I've tried several variations and events with no
luck turning off the add new row on this child table.

Anyone have any suggestions?

Tyke
 
Y

Ying-Shen Yu[MSFT]

Hi Tyke,

You need handle the DataSourceChanged event of your datagrid,
and set the AllowNew=false in the event handler. Here is the code snippet,
<code>
private void dataGrid1_DataSourceChanged(object sender, System.EventArgs e)
{
CurrencyManager cm = (CurrencyManager)this.BindingContext
[this.dataGrid1.DataSource,
this.dataGrid1.DataMember];
((DataView)cm.List).AllowNew = false;
}
</code>
Does this solve your problem?

Please reply this thread to let me know if you still have problem on this
issue.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending.
 

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