Export (0) Print
Expand All
Expand Minimize

DataGridView::DefaultValuesNeeded Event

Occurs when the user enters the row for new records so that it can be populated with default values.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public:
 event DataGridViewRowEventHandler^ DefaultValuesNeeded {
	void add (DataGridViewRowEventHandler^ value);
	void remove (DataGridViewRowEventHandler^ value);
}

This event lets you populate the row for new records when the user enters the row. Initial values for the row come from the DefaultNewRowValue property of the DataGridViewCell returned by each column's CellTemplate property.

In data bound mode, all cell values for data bound columns are stored in the external data source. When the user enters the row for new records, a new row is created in the data source before the DefaultValuesNeeded event occurs. When you populate the DataGridViewRowEventArgs::Row property in your event handler, the values are added directly to the data source.

In virtual mode, after this event occurs, the CellValuePushed event occurs for each cell in the new row so that you can store the default values in your custom data store. Then, the CellValueNeeded event occurs for each cell in the new row, retrieving the values that you stored in the CellValuePushed event, which are then displayed.

For more information about handling events, see Consuming Events.

The following code example illustrates how this event can be handled. In the example, cells for the given columns are populated with default values. For the CustomerID column, the value is retrieved from a separate method (not implemented) that generates a unique customer ID.

To run this example, replace the column names with the names of the column objects from an actual DataGridView control and provide appropriate default values. When specifying columns by name, you must use the name of the column object and not the column header text.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft