Class GroupCriterionCollection

GroupCriterionCollection class

Contains a collection of GroupCriterion objects. Implements ICollection<GroupCriterion> interface.

public class GroupCriterionCollection : IList<GroupCriterion>

Properties

NameDescription
Count { get; }Gets the number of elements contained in this collection.
IsReadOnly { get; }Gets a value indicating whether this collection is read-only; otherwise, false.
ParentGroup { get; }Gets the parent of the GroupCriterion object.

Methods

NameDescription
Add(GroupCriterion)Adds the specified item to this collection.
Clear()Removes all items from this collection.
Contains(GroupCriterion)Returns true if the specified item is found in this collection; otherwise, false.
CopyTo(GroupCriterion[], int)Copies the elements of this collection to the specified array, starting at the specified array index.
GetEnumerator()Returns an enumerator for this collection.
Remove(GroupCriterion)Removes the first occurrence of a specific object from this collection.
ToList()Converts a GroupCriterion collection to a list of GroupCriterion objects.

Examples

Shows how to work with a collection of group criterion.

var project = new Project(DataDir + "ReadGroupDefinitionData.mpp");

var group = project.TaskGroups.ToList()[0];

// iterate over group criterion
Console.WriteLine("Print group criteria of {0} group: ", group.GroupCriteria.ParentGroup.Name);
Console.WriteLine("Group criterion count: " + group.GroupCriteria.Count);
foreach (var criterion in group.GroupCriteria)
{
    Console.WriteLine("Index: " + criterion.Index);
    Console.WriteLine("Field: " + criterion.Field);
    Console.WriteLine("Group On: " + criterion.GroupOn);
    Console.WriteLine();
}

group.GroupCriteria.Clear();

if (!group.GroupCriteria.IsReadOnly)
{
    List<GroupCriterion> groupCriteria = group.GroupCriteria.ToList();
    foreach (var criterion in groupCriteria)
    {
        group.GroupCriteria.Remove(criterion);
    }
}

var criterionToAdd = new GroupCriterion
{
    Ascending = true,
    Field = Field.TaskActive
};

if (!group.GroupCriteria.Contains(criterionToAdd))
{
    group.GroupCriteria.Add(criterionToAdd);
}

// copy criteria to other group
var otherGroup = project.TaskGroups.ToList()[0];

var criteria = new GroupCriterion[group.GroupCriteria.Count];
group.GroupCriteria.CopyTo(criteria, 0);
foreach (var criterion in criteria)
{
    otherGroup.GroupCriteria.Add(criterion);
}

See Also