private void FinalizeBindings() { BindingSource.EndEdit(); GridViewSupplierCountry.CloseEditor(); GridViewSupplierCountry.UpdateCurrentRow(); //Set the city code for each mapping just in case for (int rowCtr = 0; rowCtr < GridViewSupplierCountry.DataRowCount; rowCtr++) { SupplierCountry suppCountry = (SupplierCountry)GridViewSupplierCountry.GetRow(rowCtr); suppCountry.Country_Code = TextEditCode.Text; } BindingSourceSupplierCountry.EndEdit(); }
void ClearBindings() { _ignoreLeaveRow = true; _ignorePositionChange = true; _selectedRecord = null; BindingSourceSupplierCountry.Clear(); SetReadOnly(true); BarButtonItemDelete.Enabled = false; BarButtonItemSave.Enabled = false; BindingSource.DataSource = typeof(COUNTRY); _ignoreLeaveRow = false; _ignorePositionChange = false; }
private void RemoveRecord() { if (_selectedRecord.IsNew()) { //If you clear the bindingsource for child records where the parent entity is tracked by //the context, it will lose tracking for the child entities and cascade operations like //delete will fail BindingSourceSupplierCountry.Clear(); } //Note that cascade delete must be set on the FK in the db in order for the related //entities to be deleted. This is a db function, not an EF function. However in addition //the model must know about the delete, otherwise the relationships in the context will //get messed up. So after adding the cascade rule to the FK, the model must be updated, //and in order to refresh a relationship the tables must be deleted and re-added //Otherwise, we could do a delete loop //If using DbContext instead of ObjectContext, we could do eg //_context.SupplierRegion.RemoveRange(_selectedRecord.SupplierRegion) BindingSource.RemoveCurrent(); }