Ah interesting I thought I had a solution to this when I reviewed Brian Noyes excellent "Data Binding with Windows Forms 2.0" book again.
In it he mentions a techinque of using the AddingNew event handler of the BindingSource object to return a new object, at which time you could default some property values according to your requirements. Therefore I added this handler
private void defectsBindingSource_AddingNew(object sender, AddingNewEventArgs e)
{
DefectEntity defect = new DefectEntity();
defect.DefectType = defectTypes[0];
defect.DefectSeverity = defectSeverities[0];
e.NewObject = defect;
}
However after executing thie code I received an exception from this source
/// <summary>
/// Not supported. Use AddNew() or add a new object to the related entity collection.
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
int IList.Add( object value )
{
if( value == null )
{
// design time databinding.
IEntityCore newEntity = this.AddNew();
return this.IndexOf((TEntity)newEntity);
}
throw new NotSupportedException( "Add a new object to the related collection instead, or use IBindingList.AddNew() on this object." );
}
In the EntityViewBase LLBLGen class. I don't quite understand why this method is not supported?
You can see a detailed call stack below
" at SD.LLBLGen.Pro.ORMSupportClasses.EntityViewBase`1.System.Collections.IList.Add(Object value)\r\n at System.Windows.Forms.BindingSource.Add(Object value)\r\n at System.Windows.Forms.BindingSource.AddNew()\r\n at System.Windows.Forms.CurrencyManager.AddNew()\r\n at System.Windows.Forms.DataGridView.DataGridViewDataConnection.AddNew()\r\n at System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnNewRowNeeded()\r\n at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred)\r\n at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)\r\n at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown)\r\n at System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)\r\n at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)\r\n at