Compartilhar via


TableCellCollection.AddRange(TableCell[]) Método

Definição

Acrescenta os objetos TableCell da matriz especificada ao final da coleção.

public:
 void AddRange(cli::array <System::Web::UI::WebControls::TableCell ^> ^ cells);
public void AddRange (System.Web.UI.WebControls.TableCell[] cells);
member this.AddRange : System.Web.UI.WebControls.TableCell[] -> unit
Public Sub AddRange (cells As TableCell())

Parâmetros

cells
TableCell[]

A matriz que contém os objetos TableCell a serem adicionados à coleção.

Exceções

O valor do parâmetro cells é null.

Exemplos

O exemplo a seguir demonstra como usar o AddRange método para adicionar os TableCell objetos de uma matriz a um TableCellCollection. Observe que, no exemplo, a Cells propriedade da TableRow é uma instância da TableCellCollection classe.

void Page_Load(Object sender, EventArgs e) 
{
    int numRows = 3;
    int numCells = 2;
    // Create 3 rows, each containing 2 cells.
    for(int rowNum = 0; rowNum < numRows; rowNum++) 
    {
        TableCell[] arrayOfTableRowCells = 
            new TableCell[numCells];
        TableRow tRow =  new TableRow();

        for (int cellNum = 0; cellNum < numCells; cellNum++)
        {
            TableCell tCell =  new TableCell();
            tCell.Text = 
                String.Format("[Row {0}, Cell {1}]", 
                    rowNum, cellNum);
            arrayOfTableRowCells[cellNum] = tCell;
        } 

        // Get 'TableCellCollection' associated 
        // with the 'TableRow'.
        TableCellCollection myTableCellCol = tRow.Cells;
        // Add a row of cells. 
        myTableCellCol.AddRange(arrayOfTableRowCells);
        Table1.Rows.Add(tRow);
    } 
}
Sub Page_Load(ByVal sender As Object, _
    ByVal e As EventArgs)

    Dim numRows As Integer = 3
    Dim numCells As Integer = 2
    ' Create 3 rows, each containing 2 cells.
    Dim rowNum As Integer
    For rowNum = 0 To numRows - 1
        Dim arrayOfTableRowCells(numCells - 1) As TableCell
        Dim rw As New TableRow()
        Dim cellNum As Integer
        For cellNum = 0 To numCells - 1
            Dim cel As New TableCell()
            cel.Text = _
                String.Format("[Row {0}, Cell {1}]", rowNum, cellNum)
            arrayOfTableRowCells(cellNum) = cel
        Next

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

Comentários

Use o AddRange método para acrescentar os TableCell objetos da matriz especificada à coleção. Esse método é comumente usado quando você está construindo uma linha de uma tabela. Para construir uma linha de uma tabela, primeiro crie uma matriz de TableCell objetos para representar as células da linha. Em seguida, use o AddRange método, passando a matriz como um argumento, para adicionar os TableCell objetos à coleção.

Aplica-se a

Confira também