This is a problem that is not serious, just cosmetically anoying. Apparently yours not supposed to use the .add() method to add a entity to an existing collection, not sure why. This is is as I alwasy have to do in any application is have a grid representing a collection. I put up a dialog
to create a new item, and pass the collection to the dialog. Them I use collection.addnew to create my new entity and bind that to all the text fields in the dialog box. I enter values, and then I click ok and the collection saves the values. This work fine, but when the dialog come up, the new entiry is mirrored in the datagrid, and as you enter values the values appear to the Datagrid as you type. Its just messy becuase I don't want anything added to the collection, at least visably untill the dialog is acepted and close. I there a way to keep the databinding from showing in the grid until you click OK and close trhe dialog. I don;t want to use collection.add() but it seems like the only way to make a cosmetically correct user interface.
Code: Here I pass the collection to the dialog
private void newSalesOrderItemToolStripMenuItem_Click(object sender, EventArgs e)
{
if (m_salesOrderHeader != null)
{
OrderItemEdit orderItemEdit = new OrderItemEdit(m_saleOrderDetailCollection, false );
if (orderItemEdit.ShowDialog()== DialogResult.OK )
{
m_saleOrderDetailCollection.Save();
}
else{ m_saleOrderDetailCollection.RejectChanges(); }
}
}
Code: Here the collection spawns a new entity with addNew(), and starts mirroring changes in the grid, I don;t want that
public OrderItemEdit(BusinessObjects.SalesOrderDetailCollection salesOrderItemCollection, bool IsEdit)
{
InitializeComponent();
this.m_salesOrderItems = salesOrderItemCollection;
m_orderItem = m_salesOrderItems.AddNew();
bs.DataSource = typeof(BusinessObjects.SalesOrderDetail);
bs.DataSource = m_orderItem;
BindTextFields();
}
Richard Young