dotnetmonitor.com

 
Index
Previous
Next

 

When the user selects the row for new records as the current row, the DataGridView control raises the DefaultValuesNeeded event. This event provides access to the new DataGridViewRow and enables you to populate the new row with default data.

 

The following code example demonstrates how to specify default values for new rows using the DefaultValuesNeeded event.

private void dataGridView1_DefaultValuesNeeded(object sender,

DataGridViewRowEventArgs e)

{

e.Row.Cells["Region"].Value = "WA";

e.Row.Cells["City"].Value = "Redmond";

e.Row.Cells["PostalCode"].Value = "98052-6399";

e.Row.Cells["Region"].Value = "NA";

e.Row.Cells["Country"].Value = "USA";

e.Row.Cells["CustomerID"].Value = NewCustomerId();

}

What is the DataGridView
Differences between the DataGridView and DataGrid controls
Highlight of features
Structure of DGV
Architecture Elements
Cells and Bands