IWbsFieldsRepository Interface

Provides access to WBS fields in an estimate and to their management.
Public Interface IWbsFieldsRepository
This language is not supported or no code example is available.
public interface IWbsFieldsRepository
This language is not supported or no code example is available.
Name Description
Public property ReservedVirtualFields Gets the reserved virtual fields that are not real full-featured WBS fields. These fields are hidden and reserved for system and cannot be accessed from the fields manager.
Public property Validator Gets the fields validator used by this repository when adding or updating fields. Useful to validate the data before they are sent to the repository.
Top
Methods
 
Name Description
Public method AddField(IWbsField) Adds a new field.
Public method CreateFieldInstance(WbsFieldKind, string) The factory method that creates new IWbsField objects. The new field object is not added to the repository.
Public method DeleteField(int) Deletes a field.
Public method EvaluateLocalizedFormula(string) Evaluates a localized Excel formula if needed, e.g. '=BoQXLS_Item'.
Public method GetAllFields() Gets all WBS fields.
Public method GetField(int) Gets a field with a specified IWbsField.NumericID.
Public method GetFieldByMnemonic(string) Gets the field with a specified IWbsField.Mnemonic. The search is case-insensitive.
Public method GetFields() Gets all top-level WBS fields that are available to the admin.
Public method GetReferencedFieldOfProgressField(IWbsField) Gets the target referenced field of a progress field from all fields in the repository.
Public method ImportWbsFieldsFromRepository(IWbsFieldsRepository) Imports and replaces all WBS fields from another fields repository (from another estimate).
Public method IsColumnVisible(IWbsField) Indicates whether a field's column is visible in the current context. All available settings and permissions are taken into account.
Public method IsFieldAvailableToAdmin(IWbsField) Indicates whether a field is available to admin. In other words, whether it is not reserved for system.
Public method LoadLayoutFromFile(string) Loads the layout of the WBS fields in the expanded WBS view from the specified *.clb file.
Public method Reload() Reloads the repository from the persistent state and creates new IWbsField instances. All changes that were not explicitly applied with AddField, DeleteField and UpdateField will be lost.
Public method RepaintWbsWithChanges() Repaints the WBS workbook with all changes that were made from the last call to this method. Call this method after you done all changes. You may also call slower IEstimate.CheckAndRepaint method instead.
Public method ResetLayoutForAllUsers() Resets the customized layout of the WBS fields of all users, so that they will have the same settings as the administrator, with possible exceptions due to permissions.
Public method SaveLayoutToFile(string) Saves the layout of the WBS fields in the expanded WBS view to the specified *.clb file.
Public method SetFieldDefaultAllowedContexts(IWbsField) Sets the default IWbsField.DisplayContext and IWbsField.EditContext values of a WBS field.
Public method SetFieldDefaultNameAndSubheader(IWbsField, IEnumerable<IWbsField>, bool) Sets the default (native) IWbsField.FieldName and IWbsField.SubHeader values of a WBS field.
Public method SetFieldPosition(IWbsField, FieldPlacementPosition, IWbsField, FieldUserScope) Sets the position of the specified field for specified users. The position is set relatively to another field position.
Public method UpdateField(IWbsField, bool) Updates a field, whether the complete definition or just the formatting for the current user.
Public method UpdateField(IWbsField, bool, FieldUserScope) Updates a field, whether the complete definition or just the formatting for the specified users.
Public method UpdateWithChangedMnemonics(IDictionary<StringString>) Updates WBS fields when mnemonics of some WBS fields were changed.
Top
Remarks
 

The repository caches the field instances, so normally, you always get the same IWbsField instance for a specific field. This improves performance, but it has one downside when you modify properties of the fields. As soon as you change some property of a IWbsField instance, the change is automatically available to other callers to the repository. The Reload method helps to solve the problem.

The Reload method detaches old cached instances and creates new instances of IWbsField that will be returned by next calls to GetFields, GetAllFields and GetField methods. All existing instances that were previously retrieved are detached from the repository. So you can make any changes to them and they will not be reflected in the repository, until you explicitly apply them with AddField, DeleteField and UpdateField.

This is especially useful when editing the fields. You can retrieve fields from the repository and then call the Reload method. Then you can freely change properties of the retrieved fields. Meanwhile, other users or code can access the repository and they get the correct original fields without your intermediate changes. When you are done, you can apply the changes back to the repository and they become available globally.

Example
 

// Create and format a new free WBS field MYFIELD.
 
 // Create a field instance, a unique numeric ID will be generated automatically.
 IWbsField newWbsField = es.WbsFieldsRepository.CreateFieldInstance(WbsFieldKind.FreeField, "MYFIELD");
 newWbsField.FieldName = "My new field";
 newWbsField.SubHeader = "created by a macro";
 
 // Add the new field to the repository.
 es.WbsFieldsRepository.AddField(newWbsField);
 
 // Change the formatting of the field. These settings are user-specific.
 // Do it for all users now.
 // First, make the field visible because all newly added fields are hidden and placed at the very end.
 newWbsField.Formatting.HiddenByAdmin = false;
 newWbsField.Formatting.HiddenByUser = false;
 // Change some formatting.
 newWbsField.Formatting.ColumnWidth = 20;
 newWbsField.Formatting.Header1Formatting.ForeColor = System.Drawing.Color.Red;
 newWbsField.Formatting.Header2Formatting.ForeColor = System.Drawing.Color.DarkGreen;
 newWbsField.Formatting.DataFormatting.BackgroundColor = System.Drawing.Color.LightPink;
 
 // Apply the formatting changes to the repository (no UI repainting yet).
 es.WbsFieldsRepository.UpdateField(newWbsField, false, FieldUserScope.AllUsers);
 
 // Change the column position. Don't set newWbsField.Formatting.ColumnPosition directly, as this is unreliable.
 // Instead, use SetFieldPosition, which takes care of possible problems.
 // Place the field after Quantity column. Even if Quantity column is at a different position for each user,
 // the SetFieldPosition takes care of it and it places the field in all user profiles correctly.
 IWbsField quantityField = es.WbsFieldsRepository.GetFieldByMnemonic("WBS_Quantity");
 es.WbsFieldsRepository.SetFieldPosition(newWbsField,
     FieldPlacementPosition.AfterGivenField,
     quantityField,
     FieldUserScope.AllUsers);
 
 // Repaint the changes. Normally, if the position of an EXISTING field is changed, you must call slow CheckAndRepaint().
 // But since we have changed the position of a NEWLY ADDED field, we can use much faster RepaintWbsWithChanges().
 es.WbsFieldsRepository.RepaintWbsWithChanges();					
This language is not supported or no code example is available.

The following example creates a new free WBS field, changes its formatting. At the end, the position of the new field is set to be right after the "WBS_Quantity" field. And this is done for all users, not for just the current one.

Version
 
Available since QDV 7.18.655.

.NET Framework

Supported in: 4.8, 4.7, 4.6, 4.5.2

In this article

Definition