TableCellCollection.AddRange メソッド
アセンブリ: System.Web (system.web.dll 内)



AddRange メソッドを使用して、指定した配列の TableCell オブジェクトをコレクションに追加します。このメソッドは、通常、テーブルの行を構築しているときに使用します。テーブルの行を構築するには、最初に、行のセルを表すために TableCell オブジェクトの配列を作成します。次に、AddRange メソッドを使用し、引数としてこの配列を渡して、TableCell オブジェクトをコレクションに追加します。

AddRange メソッドを使用して、配列の TableCell オブジェクトを TableCellCollection に追加する方法の例を次に示します。この例では、TableRow の Cells プロパティは、TableCellCollection クラスのインスタンスです。
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
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); } }
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.set_Text("[Row " + System.Convert.ToString(i) + ", Cell " + System.Convert.ToString(j) + "]"); arrayOfTableRowCells .set_Item( j , myTableCell ); } // Get 'TableCellCollection' associated with the 'TableRow'. TableCellCollection myTableCellCol = myTableRow.get_Cells(); // Add a row of cells. myTableCellCol.AddRange(arrayOfTableRowCells); myTable.get_Rows().Add(myTableRow); } } //Page_Load

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- TableCellCollection.AddRange メソッドのページへのリンク