FilterCollection

FilterCollection class

Contains a list of Filter objects. Implements ICollection<Filter> interface.

public class FilterCollection : ICollection<Filter>

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.

Methods

NameDescription
Add(Filter)Adds the specified item to this collection.
Clear()Removes all items from this collection.
Contains(Filter)Returns true if the specified item is found in this collection; otherwise, false.
CopyTo(Filter[], 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(Filter)Removes the first occurrence of a specific object from this collection.
ToList()Converts a filter collection to a list of Filter objects.

Examples

Shows how to work with filter collections.

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

// iterate over task filters
Console.WriteLine("Print task filters of {0} project: ", project.Get(Prj.Name));
Console.WriteLine("Task Filters Count: " + project.TaskFilters.Count);
foreach (var filter in project.TaskFilters)
{
    Console.WriteLine("All Tasks: " + filter.Name);
    Console.WriteLine("Task Item: " + filter.FilterType);
    Console.WriteLine("Task Filters Show In Menu: " + filter.ShowInMenu);
    Console.WriteLine("Task filter ShowRelatedSummaryRows: " + filter.ShowRelatedSummaryRows);
    Console.WriteLine();
}

// iterate over resource filters
Console.WriteLine("Project.ResourceFilters count: " + project.ResourceFilters.Count);
foreach (var filter in project.ResourceFilters)
{
    Console.WriteLine("Resource Filter Item Type: Item.ResourceType: " + filter.FilterType);
    Console.WriteLine("Resource filter ShowInMenu" + filter.ShowInMenu);
    Console.WriteLine("Resource filter ShowRelatedSummaryRows: " + filter.ShowRelatedSummaryRows);
}

var otherProject = new Project(DataDir + "Blank2010.mpp");

// clear other project's filters
otherProject.TaskFilters.Clear();

// copy filters to other project
var filters = new Filter[project.TaskFilters.Count];
project.TaskFilters.CopyTo(filters, 0);

foreach (var filter in filters)
{
    otherProject.TaskFilters.Add(filter);
}

// add custom task filter
var customFilter = new Filter();
customFilter.Name = "Custom Filter";
customFilter.ShowInMenu = true;
customFilter.ShowRelatedSummaryRows = true;

if (!otherProject.TaskFilters.Contains(customFilter))
{
    if (!otherProject.TaskFilters.IsReadOnly)
    {
        otherProject.TaskFilters.Add(customFilter);
    }
}

// remove all filters
List<Filter> filtersToDelete = otherProject.TaskFilters.ToList();
foreach (var filter in filtersToDelete)
{
    otherProject.TaskFilters.Remove(filter);
}

See Also