IDimSelection.Element

Syntax

Element(ElementNumber: Integer): Integer;

Parameters

ElementNumber. Element index in selection.

Description

The Element property returns element index in the dictionary by element index in selection.

Comments

If it is supposed to perform cyclic handling of a great number of selected elements, it is recommended to use the SelectedElementArray property to get an array of selected elements, and get element index in the dictionary by means of the Element property.

Example

Sub UserProc;
Var
    MB: IMetabase;
    DimInstance: IDimInstance;
    Selection: IDimSelection;
    SelElemtnts: IDimElementArray;
    i, j: Integer;
Begin
    MB := MetabaseClass.Active;
    DimInstance := MB.ItemById("D_TO").Open(NullAs IDimInstance;
    Selection := DimInstance.Elements.Children(11).Selection;
    //Get index of the last selected element
    i := Selection.Element(Selection.SelectedCount - 1);
    Debug.WriteLine("Element index: " + i.ToString);
    //Get array of selected elements
    Selection.SelectLevel(0);
    SelElemtnts := Selection.SelectedElementArray(Null);
    For i := 0 To SelElemtnts.Count - 1 Do
        j := SelElemtnts.Element(i);
        //…
        //Further work with element indexes
        //…
    End For;
End Sub UserProc;

On executing the example:

  1. Selection of child elements of the specified element is created.

  2. Index of the last selected element is sent to the "i" variable.

  3. All elements located on the same level as the element with the 0 index are selected.

  4. An array of selected elements of the level is sent to the SelElemtnts variable.

  5. During the cycle selected elements are traversed, and element indexes in the dimension are obtained by element indexes in the selection.

See also:

IDimSelection