Element(ElementNumber: Integer): Integer;
ElementNumber. Element index in selection.
The Element property returns element index in the dictionary by element index in selection.
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.
Sub UserProc;
Var
MB: IMetabase;
DimInstance: IDimInstance;
Selection: IDimSelection;
SelElemtnts: IDimElementArray;
i, j: Integer;
Begin
MB := MetabaseClass.Active;
DimInstance := MB.ItemById("D_TO").Open(Null) As 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:
Selection of child elements of the specified element is created.
Index of the last selected element is sent to the "i" variable.
All elements located on the same level as the element with the 0 index are selected.
An array of selected elements of the level is sent to the SelElemtnts variable.
During the cycle selected elements are traversed, and element indexes in the dimension are obtained by element indexes in the selection.
See also: