Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

TableRowCollection.Insert Method

Inserts a specified item in the collection at a specified index position.

Namespace:  System.Windows.Documents
Assembly:  PresentationFramework (in PresentationFramework.dll)
public void Insert(
	int index,
	TableRow item
)

Parameters

index
Type: System.Int32

A zero-based index that specifies the position in the collection at which to insert item.

item
Type: System.Windows.Documents.TableRow

An item to insert into the collection.

Implements

IList<T>.Insert(Int32, T)
ExceptionCondition
ArgumentOutOfRangeException

Raised when index is less than 0.

ArgumentNullException

Raised when item is null.

If Count equals Capacity for this collection, the collection capacity automatically is increased before the new item is inserted. Set index equal to the value of Count, to append a new collection item to the collection.

Indices for existing collection items may be adjusted to accommodate the newly inserted collection item.

This example demonstrates some of the more common operations that can be performed on a table's row groups through the RowGroups property.

The following example creates a new table and then uses the Add method to add columns to the table's RowGroups collection.

Table tbl = new Table();
int rowGroupsToAdd = 4;
for (int x = 0; x < rowGroupsToAdd; x++)
    tbl.RowGroups.Add(new TableRowGroup());

The following example inserts a new TableRowGroup. The new column is inserted at index position 0, making it the new first row group in the table.

NoteNote

The TableRowGroupCollection collection uses standard zero-based indexing.

tbl.RowGroups.Insert(0, new TableRowGroup());

The following example adds several rows to a particular TableRowGroup (specified by index) in the table.

int rowsToAdd = 10;
for (int x = 0; x < rowsToAdd; x++)
    tbl.RowGroups[0].Rows.Add(new TableRow());

The following example accesses some arbitrary properties on rows in the first row group in the table.

// Alias the working TableRowGroup for ease in referencing.
TableRowGroup trg = tbl.RowGroups[0];
trg.Rows[0].Background = Brushes.CornflowerBlue;
trg.Rows[1].FontSize = 24;
trg.Rows[2].ToolTip = "This row's tooltip";

The following example adds several cells to a particular TableRow (specified by index) in the table.

int cellsToAdd = 10;
for (int x = 0; x < cellsToAdd; x++)
    tbl.RowGroups[0].Rows[0].Cells.Add(new TableCell(new Paragraph(new Run("Cell " + (x + 1)))));

The following example access some arbitrary methods and properties on cells in the first row in the first row group.

// Alias the working for for ease in referencing.
TableRow row = tbl.RowGroups[0].Rows[0];
row.Cells[0].Background = Brushes.PapayaWhip;
row.Cells[1].FontStyle = FontStyles.Italic;
// This call clears all of the content from this cell.
row.Cells[2].Blocks.Clear();

The following example returns the number of TableRowGroup elements hosted by the table.

int rowGroups = tbl.RowGroups.Count;

The following example removes a particular row group by reference.

tbl.RowGroups.Remove(tbl.RowGroups[0]);

The following example removes a particular row group by index.

tbl.RowGroups.RemoveAt(0);

The following example removes all row groups from the table's row groups collection.

tbl.RowGroups.Clear();

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.