Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

DataGridViewCell.DefaultNewRowValue Property

Note: This property is new in the .NET Framework version 2.0.

Gets the default value for a cell in the row for new records.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public virtual Object DefaultNewRowValue { get; }
/** @property */
public Object get_DefaultNewRowValue ()

public function get DefaultNewRowValue () : Object

Property Value

An Object representing the default value.

The DefaultNewRowValue property in the base class DataGridViewCell always returns a null reference (Nothing in Visual Basic). However, this property can be overridden in derived cell classes to return other default values.

The value returned by this property is displayed if the cell is in the row for new records. This value can be overridden by a handler for the DataGridView.DefaultValuesNeeded event when focus enters the row for new records.

The following code example demonstrates how to override the DefaultNewRowValue property in a CalendarCell class that derives from DataGridViewTextBoxCell. This example is part of a larger code example provided in How to: Host Controls in Windows Forms DataGridView Cells.

public class CalendarCell : DataGridViewTextBoxCell

    public CalendarCell()
        : base()
        // Use the short date format.
        this.Style.Format = "d";

    public override void InitializeEditingControl(int rowIndex, object 
        initialFormattedValue, DataGridViewCellStyle dataGridViewCellStyle)
        // Set the value of the editing control to the current cell value.
        base.InitializeEditingControl(rowIndex, initialFormattedValue, 
        CalendarEditingControl ctl = 
            DataGridView.EditingControl as CalendarEditingControl;
        ctl.Value = (DateTime)this.Value;

    public override Type EditType
            // Return the type of the editing contol that CalendarCell uses.
            return typeof(CalendarEditingControl);

    public override Type ValueType
            // Return the type of the value that CalendarCell contains.
            return typeof(DateTime);

    public override object DefaultNewRowValue
            // Use the current date and time as the default value.
            return DateTime.Now;

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

© 2015 Microsoft