Dictionary Selection

Various objects, in which dictionaries are used, operate such an object as dictionary selection. Dictionary selection is the collection of dictionary elements used for calculation. The IDimSelection interface works with a selection. The CreateSelection method creates dictionary selection.

Var
    MB: IMetabase;
    DimInst: IDimInstance;
    Selection: IDimSelection;
Begin
    MB := MetabaseClass.Active;
    DimInst := MB.ItemById("Dim_1").Open(NullAs IDimInstance;
    Selection := DimInst.CreateSelection;

Methods of the Select* and Deselect* of the IDimSelection interface change element list in selection.

Var
    //...
    Selection: IDimSelection;
Begin
    //...
    Selection.DeselectAll;
    Selection.SelectElement(0False);
    Selection.SelectElement(3True);
    Selection.SelectChildren(5False);

All the methods operate with end-to-end indexes of elements. To get end-to-end indexes of elements, it is recommended to use different search modes described in the Element Search section. Search condition settings enable to directly change the selection of found elements. To get end-to-end index of an element in the dictionary by element index in the selection, use the Element property.

Formed selection may be set for any component, control or passed to consumer method to be used in calculation.

Selection can be stored and further restored if required. The ToVariant, Parse, AttributeToVariant, ParseAttribute methods are used for this purpose. The example of saving and restoring selection is given in the Examples: Serializing of Dictionary Selection section.

Properties of the IDimSelection interface allow to get the list of selected elements in a different form:

See also:

Introduction