TableCellCollection.AddRange(TableCell[]) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Anexa os TableCell objetos do array especificado 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
Exceções
O valor do cells parâmetro é null.
Exemplos
O exemplo seguinte demonstra como usar o AddRange método para adicionar os TableCell objetos de um array a um TableCellCollection. Note-se que no exemplo, a Cells propriedade de o 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
Observações
Use o AddRange método para anexar os TableCell objetos do array especificado à coleção. Este método é comumente usado quando se constrói uma linha de uma tabela. Para construir uma linha de uma tabela, cria-se primeiro um array de TableCell objetos para representar as células da linha. De seguida, use o AddRange método, passando o array como argumento, para adicionar os TableCell objetos à coleção.