Adds an item to a collection.
&VarBasedOnSDTCollection.Add(&VarBasedOnSDTItem [ , Position ] )
Where:
&VarBasedOnSDTCollection
It must be a variable based on an SDT collection (or a variable based on a simple SDT and defined as a collection).
&VarBasedOnSDTItem
Variable based on the SDT item.
Position
Relative position.
Generators: .NET,
.NET Framework,
Java, Ruby (up to GeneXus X Evolution 3).
It adds an Item to the collection in a relative position: Position. If Position is omitted, or if “0” is specified, the Item is added at the end of the collection. Position starts at 1.
Before adding each element to a collection, it is necessary to create a memory space using the new operator.
Consider the following Structured Data Type (SDT) object:
Suppose you define two variables in a Web Panel object (it could be another object), as shown below:
- &Attractions: Based on the Attractions SDT (so, it is a collection of items with attractions data).
- &OneAttraction: Based on Attractions.AttractionsItem (so, its data type corresponds to an item of the collection).
The &Attractions collection is already loaded with some items and you need to add a new item.
The following Event loads an item and adds it to the collection:
Event 'add attraction to the collection'
&OneAttraction = new()
&OneAttraction.Id = &Id //a variable with value is assigned but it could be a fixed value or an attribute (if it is instantiated)
&OneAttraction.Name = &Name //a variable with value is assigned but it could be a fixed value or an attribute (if it is instantiated)
&Attractions.Add(&OneAttraction)
Endevent
Structured Data Type methods