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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Prevent Datagrid to create a default empty row

Thread ID:

Created:

Updated:

Platform:

Replies:

5184 Jun 24,2003 05:34 AM Jan 22,2004 11:34 PM Windows Forms 3
loading
Tags: FAQ
Gabriel Schwartz
Asked On June 24, 2003 05:34 AM

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.

JJ
Replied On 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. > >

Gabriel Schwartz
Replied On 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. > > > > >

Stratovarius
Replied On January 22, 2004 11:34 PM

Thanks JJ. That worked like a charm.

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;