DataGridView.DefaultValuesNeeded Event


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

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)

member DefaultValuesNeeded : IEvent<DataGridViewRowEventHandler,

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 NIB: 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
Available since 2.0
Return to top