We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Prevent Datagrid to create a default empty row

I attached a sample solution to show my problem. When Form1 is created a new row is added with Customer ID 1. If I press ESC the row is removed. I want to prevent this default row creation. If the last line in Form1.cs is unmarked then two customers are created and no default row. I can't find anything from MSDN help on this.

3 Replies

JJ JJ June 29, 2003 12:41 PM

After the code that sets the DataSource property for your datagrid, add the following: //no adding of new rows thru dataview... CurrencyManager cm = (CurrencyManager)this.BindingContext[dataGrid1.DataSource, dataGrid1.DataMember]; ((DataView)cm.List).AllowNew = false; > I attached a sample solution to show my problem. > When Form1 is created a new row is added with Customer ID 1. > If I press ESC the row is removed. > I want to prevent this default row creation. > If the last line in Form1.cs is unmarked then two customers are created and no default row. > I can't find anything from MSDN help on this. > >


GS Gabriel Schwartz July 1, 2003 03:24 AM

The following line throws an exception since casting (cm.List as DataView) returns null; ((DataView)cm.List).AllowNew = false; > After the code that sets the DataSource property for your datagrid, add the following: > > //no adding of new rows thru dataview... > > CurrencyManager cm = (CurrencyManager)this.BindingContext[dataGrid1.DataSource, dataGrid1.DataMember]; > > ((DataView)cm.List).AllowNew = false; > > > I attached a sample solution to show my problem. > > When Form1 is created a new row is added with Customer ID 1. > > If I press ESC the row is removed. > > I want to prevent this default row creation. > > If the last line in Form1.cs is unmarked then two customers are created and no default row. > > I can't find anything from MSDN help on this. > > > > >


ST Stratovarius January 22, 2004 11:34 PM

Thanks JJ. That worked like a charm.

Loader.
Live Chat Icon For mobile
Up arrow icon