Class GroupCollection
Contents
[
Hide
]GroupCollection class
Contains a list of Group
objects. Implements ICollection<Group> interface.
public class GroupCollection : ICollection<Group>
Properties
Name | Description |
---|---|
Count { get; } | Gets the number of elements contained in this collection. |
IsReadOnly { get; } | Gets a value indicating whether this collection is read-only. |
Methods
Name | Description |
---|---|
Add(Group) | Adds the specified item to this collection. |
Clear() | Removes all items from this collection. |
Contains(Group) | Returns true if the specified item is found in this collection; otherwise, false. |
CopyTo(Group[], 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(Group) | Removes the first occurrence of a specific object from this collection. |
ToList() | Converts a group collection to a list of Group objects. |
Examples
Shows how to work with collection of groups.
var project = new Project(DataDir + "ReadGroupDefinitionData.mpp");
// iterate over task groups
Console.WriteLine("Print task groups of {0} project: ", project.Get(Prj.Name));
Console.WriteLine("Task Group Count: " + project.TaskGroups.Count);
foreach (var group in project.TaskGroups)
{
Console.WriteLine("Index: " + group.Index);
Console.WriteLine("Name: " + group.Name);
Console.WriteLine("Show In Menu: " + group.ShowInMenu);
Console.WriteLine();
}
// iterate over resource groups
Console.WriteLine("Project resource group count: " + project.ResourceGroups.Count);
foreach (var group in project.ResourceGroups)
{
Console.WriteLine("Resource group Index: " + group.Index);
Console.WriteLine("Resource group Name: " + group.Name);
Console.WriteLine("Resource group ShowInMenu" + group.ShowInMenu);
}
var otherProject = new Project(DataDir + "Blank2010.mpp");
// clear other project's groups
otherProject.TaskGroups.Clear();
// copy groups to other project
var groups = new Group[project.TaskGroups.Count];
project.TaskGroups.CopyTo(groups, 0);
foreach (var group in groups)
{
otherProject.TaskGroups.Add(group);
}
// add custom task group
var customGroup = new Group
{
Name = "Custom Group",
ShowInMenu = true
};
if (!otherProject.TaskGroups.Contains(customGroup))
{
if (!otherProject.TaskGroups.IsReadOnly)
{
otherProject.TaskGroups.Add(customGroup);
}
}
// remove all groups
List<Group> groupsToDelete = otherProject.TaskGroups.ToList();
foreach (var group in groupsToDelete)
{
otherProject.TaskGroups.Remove(group);
}
See Also
- class Group
- namespace Aspose.Tasks
- assembly Aspose.Tasks