TableCellCollection.AddRange(TableCell[]) Metodo

Definizione

Accoda gli oggetti TableCell dalla matrice specificata alla fine dell'insieme.

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())

Parametri

cells
TableCell[]

Matrice contenente gli oggetti TableCell da aggiungere all'insieme.

Eccezioni

Il valore del parametro cells è null.

Esempio

Nell'esempio seguente viene illustrato come utilizzare il AddRange metodo per aggiungere gli TableCell oggetti da una matrice a un oggetto TableCellCollection. Si noti che nell'esempio la Cells proprietà di TableRow è un'istanza della 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

Commenti

Utilizzare il AddRange metodo per accodare gli TableCell oggetti dalla matrice specificata all'insieme. Questo metodo viene comunemente usato quando si costruisce una riga di una tabella. Per costruire una riga di una tabella, creare prima di tutto una matrice di TableCell oggetti per rappresentare le celle della riga. Usare quindi il AddRange metodo , passando la matrice come argomento, per aggiungere gli TableCell oggetti alla raccolta.

Si applica a

Vedi anche