private void DeleteUserDefinedDataByPicklist(UserDataCategoryList listCategories) { foreach (UserDataCategory category in listCategories) { foreach (UserDataField field in category) { if ((field.Type == UserDataField.FieldType.Picklist) && (field.Value1 == Name)) { field.Delete(); } } } }
/// <summary> /// Delete the current PickList from the database /// </summary> public void Delete() { // Is this Picklist referenced by any User Defined Data Fields? To find out we will need // to recover a list of all User Defined Data Fields and check each UserDataCategoryList listCategories = new UserDataCategoryList(UserDataCategory.SCOPE.Any); listCategories.Populate(); // Iterate through the categories foreach (UserDataCategory category in listCategories) { // ...and through each field looking for Picklists foreach (UserDataField field in category) { if ((field.Type != UserDataField.FieldType.Picklist) || (field.Value1 != this.Name)) { continue; } if (MessageBox.Show( String.Format("The picklist '{0}' is used by one or more user-defined data fields." + Environment.NewLine + Environment.NewLine + "Do you wish to delete the picklist AND all related user-defined data fields?", Name ), "Delete picklist", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { DeleteUserDefinedDataByPicklist(listCategories); new PicklistsDAO().PickListDelete(_picklistID); return; } else { return; } } } // got here because of no references in user-defined data so just delete the picklist new PicklistsDAO().PickListDelete(_picklistID); }