Sorry for not providing more information before. I was thinking maybe someone else tried to go through the Rapid C# development book using LLBLGen 2.0 and had seen the same thing.
Here are some more details.
- Set up an project against the AdventureWorks database
- Use the Self-Servicing, 2 Class template
- Build an Order Search form, with a DataGridView control to list the orders
- The DataGridView is data-bound to Orders, defined as:
SalesOrderHeaderCollection Orders = new SalesOrderHeaderCollection();
Orders.GetMulti(Filter, 100, Sort, Relations);
- Set the cell content double-click event to do the following:
SalesOrderHeaderEntity Order = dgvResults.Rows[e.RowIndex].DataBoundItem as SalesOrderHeaderEntity;
frmOrderEdit OrderEdit = new frmOrderEdit(this, Order);
((frmMain)this.MdiParent).LaunchChildForm(OrderEdit);
-
In the frmOrderEdit form, keep a reference of the Order passed in with a member variable _order.
-
When the user clicks the delete button on the form:
if (MessageBox.Show("Are you sure you want to delete this order?", "Confirm Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
_order.Delete();
this.Close();
}
- When YES is clicked, _order.Delete() is successfully called. When this.close() is called, an exception occurs while the DataGridView in the other form tries to re-paint. Here's the call stack:
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, BindingFlags invokeAttr, Binder binder, Object[] index, CultureInfo culture)
at System.Reflection.RuntimePropertyInfo.GetValue(Object obj, Object[] index)
at SD.LLBLGen.Pro.ORMSupportClasses.EntityPropertyDescriptor.GetValue(Object component)
at System.Windows.Forms.DataGridView.DataGridViewDataConnection.GetValue(Int32 boundColumnIndex, Int32 columnIndex, Int32 rowIndex)
I am using WinForms C# 2.0 with LLBLGen Pro 2.0.0.0 Demo.
I chatted with a colleague about this, and I understand why it's happening. I am deleting an entity that is contained within a collection that is bound to a DataGridView. Rather than passing a reference to the entity into the edit form, I could pass its ID and get a new instance of the entity. But since the Rapid C# Development book was passing a reference to the entity and deleting it, without getting this error, I thought I'd see if this is something that I should be able to do.
Thanks!