为生成的新行添加默认值

当用户选择新行作为当前行,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        }
原文地址:https://www.cnblogs.com/maozhh/p/904395.html