void ClearBindings() { _ignoreLeaveRow = true; _ignorePositionChange = true; _selectedRecord = null; BindingSourceSupplierRegion.Clear(); SetReadOnly(true); BarButtonItemDelete.Enabled = false; BarButtonItemSave.Enabled = false; BindingSource.DataSource = typeof(REGION); _ignoreLeaveRow = false; _ignorePositionChange = false; }
private void FinalizeBindings() { BindingSource.EndEdit(); GridViewSupplierRegion.CloseEditor(); GridViewSupplierRegion.UpdateCurrentRow(); //Set the city code for each mapping just in case for (int rowCtr = 0; rowCtr < GridViewSupplierRegion.DataRowCount; rowCtr++) { SupplierRegion suppRegion = (SupplierRegion)GridViewSupplierRegion.GetRow(rowCtr); suppRegion.Region_Code = TextEditCode.Text; } BindingSourceSupplierRegion.EndEdit(); }
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 BindingSourceSupplierRegion.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(); }