How-to
Initialize AFUOMDropDown and AFTypesDropDown: which database
Short answer
Initialize OSIsoft.AF.UI.AFUOMDropDown with the UOMDatabase of the PI system that owns the attribute, and AFTypesDropDown with the AFDatabase that holds it, because enumeration sets are defined per database. Restore an existing type by building an AFType from the array flag or the enumeration-set qualifier, and read the picked value back from AFSelection through OriginalObject.

On this page
AFUOMDropDown and AFTypesDropDown take different initialization objects: the unit dropdown is initialized with the UOMDatabase of the PI system that owns the attribute, and the type dropdown with the AFDatabase that holds it, because enumeration sets are defined per AF database. Both calls go through InitializeObject, both hand the picked item back through AFSelection, and arrays and enumeration sets need an AFType built with the matching constructor before either control can show or return them. Reference help for these controls is thin — the local PIPC\help\AFUIRef.chm file lists the API but few usage patterns — so the working calls, the selection read-back and the type mappings are laid out below.
Which object each control needs #
The two scopes differ, and the difference is the whole initialization question:
| Control | InitializeObject input |
Scope |
|---|---|---|
OSIsoft.AF.UI.AFUOMDropDown |
a UOMDatabase, a property of a PISystem |
unit definitions belong to the PI system |
OSIsoft.AF.UI.AFTypesDropDown |
an AFDatabase, for example the default database of the default system |
enumeration sets are defined per AF database |
afuomDropDown1.InitializeObject(
new PISystems().DefaultPISystem.UOMDatabase);
afTypesDropDown1.InitializeObject(
new PISystems().DefaultPISystem.Databases.DefaultDatabase);
afuomDropDown1 and afTypesDropDown1 are the two control instances on the editor form. The default system is correct when the editor targets it; an editor that lets the operator choose a PI system must pass the chosen system's UOMDatabase and the database that holds the attribute under edit, or the screen presents units and types from a context other than the one being edited. Hand the types control system-level variables and it has no database to enumerate, so it does not populate — when either dropdown comes up empty, the initialization object is the first thing to inspect.
The database scope is deliberate: enumeration sets live in AF databases, and the choice of set matters wherever one drives status, as the guidance on selecting AF enumeration sets for PI Vision status displays lays out for display use.
Wiring order in the editor #
Wire the editor in this order:
- Identify the PI system and the AF database the attribute belongs to before touching either control.
- Initialize the unit dropdown with that system's
UOMDatabase. - Initialize the type dropdown with that database.
- Restore the stored definition by mapping the attribute's
TypeandTypeQualifierto anAFType(the mapping is below). - Handle
SelectedIndexChanged, readAFSelection, and passOriginalObjectto the attribute-assignment code. - Test the round trip: populated lists from the intended scope, the stored selection restored, and a write-back the database accepts.
A populated dropdown proves initialization worked, not that the editor writes the correct definition — treat population, displayed text, selected objects and saved attribute metadata as separate checks.
Read the unit selection with AFSelection #
Handle SelectedIndexChanged and read AFSelection from the unit dropdown. The selection is the unit object, not the text painted in the list: the object carries Name and Abbreviation as separate properties, and a unit-class grouping label is not interchangeable with the unit that gets assigned to the attribute. Use the selected object as the data value and its descriptive properties for presentation only.
The built-in control has no setting that switches its labels to abbreviations. If the operator must see abbreviations, populate your own list from the same UOMDatabase: its UOMClasses collection gives the unit-of-measure classes and its UOMs collection the individual units. Keep the unit object behind each entry and render Abbreviation as the visible text.
| Design | Data source | Use it when |
|---|---|---|
Built-in AFUOMDropDown |
the UOMDatabase passed to InitializeObject |
the name-based list is acceptable |
| Own list or combo box | UOMDatabase.UOMClasses and UOMDatabase.UOMs |
the screen must group by class or show abbreviations |
Commission either design the same way: pick two different units and confirm AFSelection returns the intended unit object each time, independent of the label shown.
Restore an existing type in the types dropdown #
An attribute definition reaches the control only after conversion to OSIsoft.AF.UI.AFType. Three kinds of definition, three mappings:
| Attribute kind | Test on the template | Constructor |
|---|---|---|
| Array | attrToConvert.Type.IsArray is true |
new OSIsoft.AF.UI.AFType(attrToConvert.Type, true) |
| Enumeration set | TypeQualifier holds an AFEnumerationSet |
new OSIsoft.AF.UI.AFType(attrToConvert.TypeQualifier) |
| Basic or object type | both tests miss | new OSIsoft.AF.UI.AFType(attrToConvert.Type) |
Test the array condition first, the enumeration-set qualifier second, and fall back to the plain type constructor only when both miss.
Worked example: an attribute template typed by an enumeration set #
Inputs, all read from the AF database under edit:
attrToConvert, anAFAttributeTemplatewhose type the editor must restore.attrToConvert.TypeisSystem.Int32in this example — the numeric basic type an enumeration-backed attribute carries.attrToConvert.TypeQualifieris theAFEnumerationSetdefined in that database.
The rule in words: apply the mappings in order — array, then enumeration-set qualifier, then plain type — and hand the resulting AFType to the control as the selection to display. The helper that does it:
public static OSIsoft.AF.UI.AFType GetTypeAttribute(AFAttributeTemplate attrToConvert)
{
OSIsoft.AF.UI.AFType returnType;
if (attrToConvert.Type.IsArray)
{
returnType = new OSIsoft.AF.UI.AFType(attrToConvert.Type, true);
}
else if (attrToConvert.TypeQualifier != null &&
attrToConvert.TypeQualifier.GetType() == typeof(AFEnumerationSet))
{
returnType = new OSIsoft.AF.UI.AFType(attrToConvert.TypeQualifier);
}
else
{
returnType = new OSIsoft.AF.UI.AFType(attrToConvert.Type);
}
return returnType;
}
Branch by branch on this example:
attrToConvert.Type.IsArray— anInt32is not an array, so this evaluates false and the array branch is skipped.attrToConvert.TypeQualifier != nullevaluates true, andattrToConvert.TypeQualifier.GetType() == typeof(AFEnumerationSet)evaluates true, so the qualifier branch runs andreturnTypebecomesnew OSIsoft.AF.UI.AFType(attrToConvert.TypeQualifier).- The final
elsenever executes.
Result: returnType wraps exactly the enumeration set stored on the template, and assigning it as the dropdown's selection highlights that set in the list. The test that proves it: open the dropdown, pick the same set by hand, and compare — the OriginalObject behind AFSelection must be the same AFEnumerationSet instance on both paths.
The decision, case by case: an array type (IsArray true) always takes the two-argument constructor with true; a non-array carrying an AFEnumerationSet qualifier takes the qualifier constructor; anything else takes the one-argument Type constructor.
Write the selection back to the attribute #
Cast AFSelection to OSIsoft.AF.UI.AFType and take its OriginalObject; the wrapper is a UI-layer type and is not what the attribute stores. For basic and object types the read-back is direct; arrays and enumeration sets were the two cases that resisted a plain read, and both resolve through OriginalObject:
var aftype = ((OSIsoft.AF.UI.AFType)afTypesDropDown1.AFSelection).OriginalObject;
AFEnumerationSet enumSet = (AFEnumerationSet)aftype;
For an enumeration pick, enumSet is the object the assignment code hands to the attribute or template. If the restored selection and a manual pick both return that same object, the editor round-trips.
Changing a type on a template cascades to every element instance built on it, so prove the round trip on a development database before pointing the editor at the production AF server.
Symptoms and the layer to check #
| Symptom | Layer to inspect | Action |
|---|---|---|
| Dropdown comes up empty | initialization object | check what was passed to InitializeObject: UOMDatabase for units, AFDatabase for types |
| Units from the wrong PI system appear | backing data context | compare the system used for initialization with the system the editing session targets |
| Basic types show, an expected enumeration set does not | backing database | confirm the AFDatabase the control received actually defines that set |
| A name is shown where an abbreviation is wanted | presentation | read Abbreviation from the unit object; it is a property, not a control setting |
| Selection changes but the attribute does not | event and assignment path | trace SelectedIndexChanged, the returned AFSelection and the write-back separately |
These are editor-side faults. A display-side problem such as a PI AF attribute with no PI Point tag in PI Vision has its own causes and is checked on the PI Vision side.
Questions asked
What happens if the wrong object is passed to InitializeObject?
AFUOMDropDown expects a UOMDatabase and AFTypesDropDown expects an AFDatabase. Pass a system-level object, the two objects swapped, or a database from a different system, and the list does not populate with the choices the editor needs. When a dropdown comes up empty, read back what the initialization call received before touching selection events, because every later step depends on that object being the right one in the right scope.
Can these controls be used outside Windows Forms?
OSIsoft.AF.UI controls are Windows Forms controls. A WPF application can host them through WindowsFormsHost, and a web client cannot use them directly. For WPF or web interfaces, build your own selector from the same objects: the UOMDatabase's UOMs for units, and the enumeration sets defined in the AF database for types, reading the chosen object back the same way.
Does the read-back differ for basic types?
Yes. For basic and object types the pick needs no special handling: AFSelection gives an AFType whose OriginalObject is the attribute's underlying type, ready to assign. Only arrays and enumeration sets need the array-aware constructor or the enumeration-set qualifier on the way in, which is why those two are the cases that break a straightforward implementation while simple types survive it.
What does the workstation running the editor need?
The OSIsoft.AF.UI assemblies come with the AF SDK, so the machine running the custom editor needs the AF client installed and a configured PI system to reach. The PISystems enumeration is built from that client configuration; if it is empty, there is no system to hand to InitializeObject and neither dropdown can be initialized.


