當用戶選擇新行作為當前行,DataGridVIEw會觸發DefaultValuesNeeded事件。在該事件中可以訪問新行,並為其生成默認值,為用戶輸入提供方便。
1 /**//// <summary>
2 /// 為生成的新行添加默認值
3 /// </summary>
4 /// <param name="sender"></param>
5 /// <param name="e"></param>
6 private void cMS_CNTRDataGridView_DefaultValuesNeeded(object sender, DataGridVIEwRowEventArgs e)
7 {
8 e.Row.Cells["Region"].Value = "WA";
9 e.Row.Cells["City"].Value = "Redmond";
10 e.Row.Cells["PostalCode"].Value = "98052-6399";
11 e.Row.Cells["Region"].Value = "NA";
12 e.Row.Cells["Country"].Value = "USA";
13 e.Row.Cells["CustomerID"].Value = NewCustomerId();
14 }