This documentation is archived and is not being maintained.

TableCellCollection.AddRange Method

Appends the TableCell objects from the specified array to the end of the collection.

[Visual Basic]
Public Sub AddRange( _
   ByVal cells() As TableCell _
)
[C#]
public void AddRange(
 TableCell[] cells
);
[C++]
public: void AddRange(
 TableCell* cells[]
);
[JScript]
public function AddRange(
   cells : TableCell[]
);

Parameters

cells
The array containing the TableCell objects to add to the collection.

Exceptions

Exception Type Condition
ArgumentNullException The value of the cells parameter is a null reference (Nothing in Visual Basic).

Remarks

Use the AddRange method to append the TableCell objects from the specified array to the collection. This method is commonly used when you are constructing a row of a table. To construct a row of a table, first create an array of TableCell objects to represent the cells of the row. Next, use the AddRange method, passing the array as an argument, to add the TableCell objects to the collection.

Example

[Visual Basic, C#] The following example demonstrates how to use the AddRange method to add the TableCell objects from an array to a TableCellCollection. Note that in the example, the Cells property of the TableRow is an instance of the TableCellCollection class.

[Visual Basic] 
Sub Page_Load(sender As Object, e As EventArgs)
   Dim numRows As Integer = 3
   Dim numCells As Integer = 2
   ' Create 3 rows, each containing 2 cells.
   Dim i As Integer
   For i = 0 To numRows - 1
      Dim arrayOfTableRowCells(numCells-1) As TableCell
      Dim myTableRow As New TableRow()
      Dim j As Integer
   For j = 0 To numCells - 1
      Dim myTableCell As New TableCell()
      myTableCell.Text = "[Row " + i.ToString() + ", Cell " + j.ToString() + "]"
      arrayOfTableRowCells(j) = myTableCell
   Next j

      ' Get 'TableCellCollection' associated with the 'TableRow'.
      Dim myTableCellCol As TableCellCollection = myTableRow.Cells
      ' Add a row of cells. 
      myTableCellCol.AddRange(arrayOfTableRowCells)
      myTable.Rows.Add(myTableRow)
   Next i
End Sub 'Page_Load

[C#] 
void Page_Load(Object sender, EventArgs e)
{
   int numRows = 3;
   int numCells = 2;
   // Create 3 rows, each containing 2 cells.
   for (int i = 0; i < numRows; i++)
   {
      TableCell[] arrayOfTableRowCells = new TableCell[numCells];
      TableRow myTableRow = new TableRow();
      for (int j = 0; j < numCells; j++)
      {
         TableCell myTableCell = new TableCell();
         myTableCell.Text = "[Row " + i.ToString() + ", Cell " 
                            + j.ToString()+ "]";
         arrayOfTableRowCells[j] = myTableCell;
      }
      
      // Get 'TableCellCollection' associated with the 'TableRow'.
      TableCellCollection myTableCellCol = myTableRow.Cells;
      // Add a row of cells. 
      myTableCellCol.AddRange(arrayOfTableRowCells);
      myTable.Rows.Add(myTableRow);
   }
}

[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

See Also

TableCellCollection Class | TableCellCollection Members | System.Web.UI.WebControls Namespace | Add | AddAt

Show: