private void FinalizeBindings() { BindingSource.EndEdit(); GridViewSupplierCity.CloseEditor(); GridViewSupplierCity.UpdateCurrentRow(); //Set the city code for each mapping just in case for (int rowCtr = 0; rowCtr < GridViewSupplierCity.DataRowCount; rowCtr++) { SupplierCity suppCity = (SupplierCity)GridViewSupplierCity.GetRow(rowCtr); suppCity.Citycod_Code = TextEditCode.Text ?? string.Empty; } BindingSourceSupplierCity.EndEdit(); }
void ClearBindings() { _ignoreLeaveRow = true; _ignorePositionChange = true; _selectedRecord = null; BindingSourceSupplierCity.Clear(); SetReadOnly(true); BarButtonItemDelete.Enabled = false; BarButtonItemSave.Enabled = false; BindingSource.DataSource = typeof(CITYCOD); ClearMapData(); //Mapping _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 BindingSourceSupplierCity.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.SupplierCity.RemoveRange(_selectedRecord.SupplierCity) BindingSource.RemoveCurrent(); }