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.

Data Grid Add New Default Value

Thread ID:





6636 Aug 20,2003 04:38 PM Jun 16,2004 12:25 PM Windows Forms 1
Tags: FAQ
Asked On August 20, 2003 04:38 PM

Hi, I have a data bound grid that is using a custom tablestyle. When the User adds a new record to my grid, I need to display a default date value in one of the cells in the addnew line of the grid. ie the add new row of the grid gets focus and a cell in that row automatically getts filled with a date.

Todd Armstrong
Replied On June 16, 2004 12:25 PM

I accomplished this through capturing the Binder.EditModeChanged event. Here''s a small sample, where grid is the databoundgrid and I''m using a typed DataRow to fill in the values. It should get you where you need to go. // In constructor this.grid.Binder.EditModeChanged += new EventHandler(Binder_EditModeChanged); // Event fires this function public void Binder_EditModeChanged(object sender, System.EventArgs e) { if (this.grid.Binder.IsEditing && this.grid.Binder.IsAddNew ) { CurrencyManager cm = (CurrencyManager)this.grid.Binder.BindingContext[this.grid.DataSource, this.grid.DataMember]; if( cm.Position != -1 ) { ContingentUsageSchedDataSet.I_CONTINGENT_USG_EDF_DTLRow row; row = (ContingentUsageSchedDataSet.I_CONTINGENT_USG_EDF_DTLRow)((DataRowView)cm.Current).Row; // RTA Hardcoded per Tom H. email. row.I_INDUSTRY_SUBSEC_ID = 29; row.EDF_1_YEAR_ICUED = 0; row.USG_FRACTION_ICUED = 0; } } }


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.

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.