ViewCollection Class

Contains a list of View objects. Implements ICollection<View> interface.
Inheritance Hierarchy
SystemObject
  Aspose.TasksViewCollection

Namespace:  Aspose.Tasks
Assembly:  Aspose.Tasks (in Aspose.Tasks.dll) Version: 21.10
Syntax
public class ViewCollection : ICollection<View>, 
	IEnumerable<View>, IEnumerable

The ViewCollection type exposes the following members.

Properties
  NameDescription
Public propertyCode exampleCount
Gets the number of elements contained in this collection.
Public propertyCode exampleIsReadOnly
Gets a value indicating whether this collection is read-only; otherwise, false.
Public propertyCode exampleParentProject
Gets the parent of the View object. Read-only Project.
Methods
  NameDescription
Public methodCode exampleAdd
Adds the specified item to this collection.
Public methodCode exampleClear
Removes all items from this collection.
Public methodCode exampleContains
Returns true if the specified item is found in this collection; otherwise, false.
Public methodCode exampleCopyTo
Copies the elements of this collection to the specified array, starting at the specified array index.
Public methodEquals (Inherited from Object.)
Protected methodFinalize (Inherited from Object.)
Public methodGetByName
Searches for a View with the name, and returns the first occurrence within the collection.
Public methodGetByViewScreen
Searches for a View with the specified Screen property, and returns the first occurrence within the collection.
Public methodCode exampleGetEnumerator
Returns an enumerator for this collection.
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Protected methodMemberwiseClone (Inherited from Object.)
Public methodCode exampleRemove
Removes the first occurrence of a specific object from this collection.
Public methodCode exampleToList
Converts a view collection to a list of View objects.
Public methodToString (Inherited from Object.)
Examples
Shows how to work with view collections.
var project = new Project(DataDir + "Project1.mpp");

// convert to a plain list of views
List<View> list = project.Views.ToList();
for (var index = 0; index < list.Count; index++)
{
    var viewToChange = list[index];
    viewToChange.PageInfo.Header.CenteredText = "Header " + index;
}

// add a new view
var view = new GanttChartView();
if (!project.Views.IsReadOnly)
{
    project.Views.Add(view);
}

// iterate over views
Console.WriteLine("Iterate over views of " + project.Views.ParentProject.Get(Prj.Name) + " project.");
Console.WriteLine("Project view count: " + project.Views.Count);
Console.WriteLine();
foreach (var projectView in project.Views)
{
    Console.WriteLine("Name: " + projectView.Name);
}

// remove all views at once
project.Views.Clear();

// or one by one
{
    // approach 1
    List<View> listToDelete = project.Views.ToList();
    foreach (var v in listToDelete)
    {
        if (project.Views.Contains(v))
        {
            project.Views.Remove(v);
        }
    }
}

{
    // approach 2
    var array = new View[project.Views.Count];
    project.Views.CopyTo(array, 0);
    foreach (var v in array)
    {
        if (project.Views.Contains(v))
        {
            project.Views.Remove(v);
        }
    }
}
See Also