Class
SheetCollection

Ordered collection of sheets in a workbook, managing sheet creation, insertion, removal, visibility, and active sheet tracking with validation and event notifications.

Definition

Namespace:Telerik.Windows.Documents.Spreadsheet.Model

Assembly:Telerik.Windows.Documents.Spreadsheet.dll

Syntax:

cs-api-definition
public class SheetCollection : IEnumerable<Sheet>, IEnumerable

Inheritance: objectSheetCollection

Implements: IEnumerableIEnumerable<Sheet>

Properties

ActiveSheet

Currently selected sheet displayed to the user; must be a sheet from this collection.

Declaration

cs-api-definition
public Sheet ActiveSheet { get; set; }

Property Value

Sheet

The active sheet.

ActiveSheetIndex

Zero-based index of the active sheet, or -1 if no sheets exist; setting updates both index and ActiveSheet.

Declaration

cs-api-definition
public int ActiveSheetIndex { get; set; }

Property Value

int

The index of the active sheet.

Count

Total number of sheets in the collection, including hidden and very hidden sheets.

Declaration

cs-api-definition
public int Count { get; }

Property Value

int

The count of the sheets.

Workbook

Workbook that owns this collection, providing the context for sheet operations.

Declaration

cs-api-definition
public Workbook Workbook { get; }

Property Value

Workbook

The workbook.

this[int]

Retrieves the sheet at the specified zero-based index.

Declaration

cs-api-definition
public Sheet this[int index] { get; }

Parameters

index

int

Property Value

Sheet

The sheet.

this[string]

Retrieves the sheet with the specified name, using case-insensitive comparison.

Declaration

cs-api-definition
public Sheet this[string sheetName] { get; }

Parameters

sheetName

string

Property Value

Sheet

The sheet.

Methods

Add(SheetType)

Creates a new sheet of the specified type with a generated unique name and appends it to the collection.

Declaration

cs-api-definition
public Sheet Add(SheetType type)

Parameters

type

SheetType

The type of sheet.

Returns

Sheet

The newly created sheet.

Contains(Sheet)

Checks whether the specified sheet exists in this collection.

Declaration

cs-api-definition
public bool Contains(Sheet sheet)

Parameters

sheet

Sheet

The sheet.

Returns

bool

The value indicating whether the sheet is contained in the collection.

Contains(string)

Checks whether a sheet with the specified name exists in the collection, using case-insensitive comparison.

Declaration

cs-api-definition
public bool Contains(string sheetName)

Parameters

sheetName

string

The name of the sheet.

Returns

bool

The value indicating whether a sheet with the specified name is contained in the collection.

GetByName(string)

Retrieves the sheet with the specified name using case-insensitive comparison, or null if not found.

Declaration

cs-api-definition
public Sheet GetByName(string sheetName)

Parameters

sheetName

string

The name of the sheet.

Returns

Sheet

The sheet.

GetEnumerator()

Returns an enumerator for iterating through all sheets in order.

Declaration

cs-api-definition
public IEnumerator<Sheet> GetEnumerator()

Returns

IEnumerator<Sheet>

A IEnumerator<T> that can be used to iterate through the collection.

Implements IEnumerable<Sheet>.GetEnumerator()

Hide()

Hides the currently active sheet, ensuring at least one visible sheet remains.

Declaration

cs-api-definition
public void Hide()

Hide(Sheet)

Hides the specified sheet, ensuring at least one visible sheet remains.

Declaration

cs-api-definition
public void Hide(Sheet sheet)

Parameters

sheet

Sheet

The sheet.

Hide(int)

Hides the sheet at the specified index, ensuring at least one visible sheet remains.

Declaration

cs-api-definition
public void Hide(int index)

Parameters

index

int

The index.

IndexOf(Sheet)

Searches for the specified sheet and returns its zero-based index, or -1 if not found.

Declaration

cs-api-definition
public int IndexOf(Sheet sheet)

Parameters

sheet

Sheet

The sheet.

Returns

int

The index of the sheet.

IndexOf(string)

Searches for a sheet with the specified name using case-insensitive comparison and returns its zero-based index, or -1 if not found.

Declaration

cs-api-definition
public int IndexOf(string sheetName)

Parameters

sheetName

string

The name of the sheet.

Returns

int

The index of the sheet.

Insert(SheetType)

Creates a new sheet of the specified type with a generated unique name and inserts it at the active sheet's index.

Declaration

cs-api-definition
public Sheet Insert(SheetType type)

Parameters

type

SheetType

The type.

Returns

Sheet

The newly created sheet.

Insert(int, SheetType)

Creates a new sheet of the specified type with a generated unique name and inserts it at the specified index.

Declaration

cs-api-definition
public Sheet Insert(int index, SheetType type)

Parameters

index

int

The index.

type

SheetType

The type.

Returns

Sheet

The newly created sheet.

Move(int, int, int)

Relocates a contiguous range of sheets from the source index to the destination index, shifting other sheets as needed.

Declaration

cs-api-definition
public void Move(int fromIndex, int itemCount, int toIndex)

Parameters

fromIndex

int

From index.

itemCount

int

The item count.

toIndex

int

To index.

OnActiveSheetChanged()

Raises the ActiveSheetChanged event, notifying subscribers of sheet change.

Declaration

cs-api-definition
protected virtual void OnActiveSheetChanged()

OnActiveSheetIndexChanged()

Raises the ActiveSheetIndexChanged event, notifying subscribers of index change.

Declaration

cs-api-definition
protected virtual void OnActiveSheetIndexChanged()

OnChanged(SheetCollectionChangedEventArgs)

Raises the Changed event, notifying subscribers of completed collection modification.

Declaration

cs-api-definition
protected virtual void OnChanged(SheetCollectionChangedEventArgs args)

Parameters

args

SheetCollectionChangedEventArgs

The SheetCollectionChangedEventArgs instance containing the event data.

Remove()

Removes the currently active sheet from the collection, ensuring at least one visible sheet remains.

Declaration

cs-api-definition
public void Remove()

Remove(Sheet)

Removes the specified sheet from the collection and returns true if found, false otherwise.

Declaration

cs-api-definition
public bool Remove(Sheet sheet)

Parameters

sheet

Sheet

The sheet.

Returns

bool

The value indicating whether the specified sheet was found.

Remove(string)

Removes the sheet with the specified name and returns true if found, false otherwise.

Declaration

cs-api-definition
public bool Remove(string sheetName)

Parameters

sheetName

string

The name of the sheet.

Returns

bool

The value indicating whether a sheet with a specified name was found.

RemoveAt(int)

Removes the sheet at the specified index, ensuring at least one visible sheet remains.

Declaration

cs-api-definition
public void RemoveAt(int index)

Parameters

index

int

The index.

Unhide(Sheet)

Makes the specified sheet visible and sets it as the active sheet.

Declaration

cs-api-definition
public void Unhide(Sheet sheet)

Parameters

sheet

Sheet

The sheet.

Unhide(int)

Makes the sheet at the specified index visible and sets it as the active sheet.

Declaration

cs-api-definition
public void Unhide(int index)

Parameters

index

int

The index.

Events

ActiveSheetChanged

Raised when the active sheet reference changes, allowing UI to switch displayed content.

Declaration

cs-api-definition
public event EventHandler ActiveSheetChanged

Event Value

EventHandler

ActiveSheetIndexChanged

Raised when the active sheet's index changes, allowing UI to update tab selection.

Declaration

cs-api-definition
public event EventHandler ActiveSheetIndexChanged

Event Value

EventHandler

Changed

Raised after a sheet operation completes (add, remove, hide, unhide, move, clear), providing change details.

Declaration

cs-api-definition
public event EventHandler<SheetCollectionChangedEventArgs> Changed

Event Value

EventHandler<SheetCollectionChangedEventArgs>