Multiple Selection. Learn More

This topic describes types, its methods and properties used for managing of Multiple Selection functional.

ObjectSet<T> class

ObjectSet<T> class is non-persistent. The developer himself has to initialize its properties or use the ObjectSetPersistentOwnerHelper class.

ObjectSet<T> class exposes the following properties and methods:


<T> parameter specifies the type of objects which forms the Selection.

GlobalContext is a calculated property. It allows you to split the objects of Selections on the basis of added modules. To indicate that while a particular module is being added, all subsequent Selections should be stored separately, it is necessary to modify the XafariModule.ObjectSetGlobalContexts collection. Add the corresponding key-value pair to it.

LocalContext is used to split/combine references to the Selection, i.e. under certain circumstances, different ObjectSet <T> instances can refer to the same Selection.

OwnerId allows you to bind the Selection to a particular object, the so-called "owner". In Getting Started, only one instance of the FilterObject class was featured. In a real project, there can be lots of such instances, and the properties of each of them should refer to "their" Selections.

SelectionType specifies a selection method, i.e. the way in which objects forming the Selection are defined. This property can be one of the values of the MultipleSelectionType enumeration:

  • None: the method of selection not defined.
  • Multiple: to selected static set of objects.
  • Criteria: to apply the criterion that selects a dynamic set of objects.

Criteria specifies the criterion for selecting objects.

KeyPropertyTypeName is a calculated property. It can contain values from the KeyPropertyTypeName enumeration. The value is calculated based on the type of the key field of the selectable objects.

ObjectsSelectableType specifies the type of the Selection.

XPObjectSet refers to a persistent object of the XPObjectSet type, this object is stored in the database.


ObjectSet(IObjectSpace objectSpace) is a constructor. The ObjectSpace parameter is used for interacting with the database.

IList GetSelectionObjects() returns a set of selected objects which corresponds to the current instance.

void SetSelectedObject (IList selectedObject) sets a static set of Selection objects. In this case, the old objects are deleted. After calling, ObjectsSelectableType property does not change automatically. If it's important, you have to set a new value manually.

int GetObjectSetObjectCount() returns the number of objects in the Selection. It uses a direct query to the database.

CriteriaOperator GetCriteria(string propertyName) returns the current criterion. This criterion may be required in the future to filter other data.

ObjectSetPersistentOwnerHelper class

As mentioned before, an instance of ObjectSet<T> class is not persistent. Properties of the ObjectSet<T> type are defined in an owner class (see. FilterObject class in the example). ObjectSetPersistentOwnerHelper will help initialize objects of the ObjectSet<T> class.

To use ObjectSetPersistentOwnerHelper successfully, the following requirements must be met:

  • property of ObjectSet<T> type in owner-class should be persistent.
  • an instance of ObjectSet<T> uses the OwnerId property, it allows the particular Selection to know its owner.

ObjectSetPersistentOwnerHelper exposes the following methods:

public static void CreateObjectSets<O>(O owner, string ownerId): to initialize all the properties of ObjectSet<T> type in the specified  owner objet.

Parameters: O specifies the type of the owner-object, owner is a reference to the owner object, ownerId is an identifier which binds the Selection to its parent object.


LocalContext property is automatically initialized by the name of the property which refers to the ObjectSet<T> object . If you want to set your own value for the LocalContext property, you can use the LocalContextAttribute attribute  (see. FilterObject_B and FilterObject_C in the example).

public static void UpdateOwnwerId<O>(O owner): updates the value of OwnerId property of all the instances of ObjectSet<T>.

Let’s examine the code of FilterObject class given in the example. When the FilterObject object is being loaded, it is required to initialize all its properties of ObjectSet<T> type. You have to override OnLoaded() method and call the class ObjectSetPersistentOwnerHelper in it.

  • c#
  • VB

protected override void OnLoaded()
  ObjectSetPersistentOwnerHelper.CreateObjectSets(this, this.Session.GetKeyValueAsString(this));

Protected Overrides Sub OnLoaded()
  ObjectSetPersistentOwnerHelper.CreateObjectSets(Me, Me.Session.GetKeyValueAsString(Me))
End Sub

However, the situation may arise when the value of the key field of the owner-object is unknown. Then you can not explicitly set the value of ownerId parameter. This can happen when a new owner-object is created. To solve the problem, we propose first initialize OwnerId property with a temporary value:

  • c#
  • VB

public override void AfterConstruction()
  ObjectSetPersistentOwnerHelper.CreateObjectSets(this, ObjectSetPersistentOwnerHelper.OwnertIdUndefined);

Public Overrides Sub AfterConstruction()
  ObjectSetPersistentOwnerHelper.CreateObjectSets(Me, ObjectSetPersistentOwnerHelper.OwnertIdUndefined)
End Sub

Once the key field in the owner-object becomes available, update OwnerId property. For calling UpdateOwnwerId method, override, for example, OnSaving() method of the base class.

  • c#
  • VB

protected override void OnSaving()

Protected Overrides Sub OnSaving()
End Sub

Additional Features


Use ObjectSetOperand in the code in order to obtain the required Selection.

  • c#
  • VB

public void smth()
  new ObjectSetOperand(propertyName, new { LocalContext, OwnerId }, KeyPropertyTypeName);

Public Sub smth()
  new ObjectSetOperand(propertyName, new (), KeyPropertyTypeName)
End Sub

Constructor parameters:

propertyName: specifies reference property name. It property refers to the object that should be in the Selection.

LocalContext, OwnerId, KeyPropertyTypeName  are properties of ObjectSet<T> type which limit the search.

ObjectSet() custom  function.

This function can be used both in runtime and Design-time. The function has 4 input parameters; the fourth one is not required:

  • example


The first parameter is a reference to the property which is used for filtration.

The second parameter specifies the name of the local context. (See LocalContext in the Selection). If the task is to filter on the Selection which does not depend on the local context, then you have to set the 'null' value.

The third parameter specifies the key field of the object owner; you have to use the string representation. If the task is to filter on the Selection that is independent of the object owner, set the 'null' value.

The fourth parameter (optional) specifies the type of the key field of the objects of the Selection; you have to use the string representation. For example, if you need to specify the Int type, then set the value to 'int'. The framework assumes that the default value is Guid.