TableCellCollection クラス

定義

Table コントロール内の行を構成する TableHeaderCell オブジェクトと TableCell オブジェクトのコレクションをカプセル化します。 このクラスは継承できません。

public ref class TableCellCollection sealed : System::Collections::IList
public sealed class TableCellCollection : System.Collections.IList
type TableCellCollection = class
    interface IList
    interface ICollection
    interface IEnumerable
Public NotInheritable Class TableCellCollection
Implements IList
継承
TableCellCollection
実装

次の例では、プログラムによってコントロールを入力する方法を Table 示します。 TableCell 個々のセルを表すオブジェクトは、プロパティを介して TableRow 個々の行を表すオブジェクトに Cells 追加されます。

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    private void Page_Load(Object sender, EventArgs e) 
    {
        // Generate rows and cells.           
        int numrows = 4;
        int numcells = 6;
        int counter = 1;
        for (int rowNum = 0; rowNum < numrows; rowNum++) 
        {          
            TableRow rw = new TableRow();
            for (int cellNum = 0; cellNum < numcells; cellNum++) 
            {
                TableCell cel = new TableCell();
                cel.Text=counter.ToString();
                counter++;
                rw.Cells.Add(cel);
            }
            Table1.Rows.Add(rw);
        }
    }
 
    private void Button_Click_Coord(object sender, EventArgs e) 
    {
        for (int rowNum = 0; rowNum < Table1.Rows.Count; rowNum++) 
        {          
            for (int cellNum = 0; cellNum < 
                Table1.Rows[rowNum].Cells.Count; cellNum++) 
            {
                Table1.Rows[rowNum].Cells[cellNum].Text = 
                    String.Format("(Row{0}, Cell{1})", rowNum, cellNum);
            }
        }
    }

    private void Button_Click_Number(object sender, EventArgs e) 
    {
        int counter = 1;
          
        for (int rowNum = 0; rowNum < Table1.Rows.Count; rowNum++) 
        {
            for (int cellNum = 0; cellNum < 
                Table1.Rows[rowNum].Cells.Count; cellNum++) 
            {
                Table1.Rows[rowNum].Cells[cellNum].Text = 
                    counter.ToString();
                counter++;
            }            
        }
    }
 
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>TableCellCollection Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>TableCellCollection Example</h3>
       <asp:Table id="Table1" 
            runat="server"/>
       <br />
       <center>
          <asp:Button id="Button1"
               Text="Display Table Coordinates"
               OnClick="Button_Click_Coord"
               runat="server"/>
          <asp:Button id="Button2"
               Text="Display Cell Numbers"
               OnClick="Button_Click_Number"
               runat="server"/>
       </center>
 
    </div>
    </form>
</body>
</html>
<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    Private Sub Page_Load(sender As Object, e As EventArgs)
        ' Generate rows and cells.           
        Dim numrows As Integer = 4
        Dim numcells As Integer = 6
        Dim counter As Integer = 1
        Dim rowNum As Integer
        Dim cellNum As Integer
        For rowNum = 0 To numrows - 1
            Dim rw As New TableRow()
            For cellNum = 0 To numcells - 1
                Dim cel As New TableCell()
                cel.Text = counter.ToString()
                counter += 1
                rw.Cells.Add(cel)
            Next
            Table1.Rows.Add(rw)
        Next
    End Sub

    Private Sub Button_Click_Coord(sender As Object, e As EventArgs)            
        Dim rowNum As Integer
        Dim cellNum As Integer
        Dim rowCount As Integer
        For rowCount = 0 To Table1.Rows.Count - 1
            For cellNum = 0 To (Table1.Rows(rowNum).Cells.Count) - 1                    
                Table1.Rows(rowNum).Cells(cellNum).Text = _
                    String.Format("(Row{0}, Cell{1})", rowNum, cellNum)
            Next
        Next
    End Sub

    Private Sub Button_Click_Number(sender As Object, e As EventArgs)
        Dim counter As Integer = 1

        Dim rowNum As Integer
        Dim cellNum As Integer
        For rowNum = 0 To Table1.Rows.Count - 1
            For cellNum = 0 To (Table1.Rows(rowNum).Cells.Count) - 1                    
                Table1.Rows(rowNum).Cells(cellNum).Text = _
                    counter.ToString()
                counter += 1
            Next 
        Next
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>TableCellCollection Example</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <h3>TableCellCollection Example</h3>
       <asp:Table id="Table1" 
            runat="server"/>
       <br />
       <center>
          <asp:Button id="Button1"
               Text="Display Table Coordinates"
               OnClick="Button_Click_Coord"
               runat="server"/>
          <asp:Button id="Button2"
               Text="Display Cell Numbers"
               OnClick="Button_Click_Number"
               runat="server"/>
       </center>
 
    </div>
    </form>
</body>
</html>

注釈

コントロール内の行を構成するオブジェクトの TableCell コレクションをプログラムで管理するには、このクラスを Table 使用します。 このクラスは、通常、コントロール内 Table の行に対してセルを追加または削除するために使用されます。

注意

Tableコントロールには、オブジェクトのコレクションをRows表すコレクションTableRowが含まれています。 それぞれがTableRowテーブル内の個々の行を表し、オブジェクトのTableCellコレクションをCells表すコレクションを含みます。 これらのオブジェクトは TableCell 、テーブル内の個々のセルを表します。 個々のセルを取得するには、まずコントロールのコレクションから a をTableRow取得するTableRows必要があります。 その後、.のコレクションTableRowから a TableCellCells取得できます。

プロパティ

Count

TableCell に含まれる TableCellCollection オブジェクトの数を取得します。

IsReadOnly

TableCellCollection が読み取り専用かどうかを示す値を取得します。

IsSynchronized

TableCellCollection へのアクセスが同期されるかどうか (スレッドセーフかどうか) を示す値を取得します。

Item[Int32]

TableCell の指定したインデックス位置にある TableCellCollection を取得します。

SyncRoot

TableCellCollection へのアクセスを同期するために使用できるオブジェクトを取得します。

メソッド

Add(TableCell)

指定した TableCellTableCellCollection の末尾に追加します。

AddAt(Int32, TableCell)

TableCell 内の指定したインデックス位置に、指定した TableCellCollection を追加します。

AddRange(TableCell[])

指定した配列の TableCell オブジェクトをコレクションの末尾に追加します。

Clear()

TableCell からすべての TableCellCollection オブジェクトを削除します。

CopyTo(Array, Int32)

指定した TableCellCollectionArray の項目をコピーします。コピー操作は、Array 内の指定したインデックス位置から始まります。

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetCellIndex(TableCell)

TableCell 内の指定した TableCellCollection のインデックスを表す値を返します。

GetEnumerator()

IEnumerator のすべての TableCell オブジェクトを格納している TableCellCollection 実装オブジェクトを返します。

GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
Remove(TableCell)

指定した TableCellTableCellCollection から削除します。

RemoveAt(Int32)

TableCell 内の指定したインデックス位置から TableCellCollection を削除します。

ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

明示的なインターフェイスの実装

IList.Add(Object)

コレクションにオブジェクトを追加します。

IList.Contains(Object)

指定したオブジェクトがコレクション内にあるかどうかを確認します。

IList.IndexOf(Object)

指定したオブジェクトを検索し、コレクション内で最初に見つかった位置の 0 から始まるインデックス番号を返します。

IList.Insert(Int32, Object)

コレクション内の指定したインデックス位置にオブジェクトを挿入します。

IList.IsFixedSize

このメンバーの詳細については、「IsFixedSize」をご覧ください。

IList.Item[Int32]

このメンバーの詳細については、「Item[Int32]」をご覧ください。

IList.Remove(Object)

オブジェクトをコレクションから削除します。

拡張メソッド

Cast<TResult>(IEnumerable)

IEnumerable の要素を、指定した型にキャストします。

OfType<TResult>(IEnumerable)

指定された型に基づいて IEnumerable の要素をフィルター処理します。

AsParallel(IEnumerable)

クエリの並列化を有効にします。

AsQueryable(IEnumerable)

IEnumerableIQueryable に変換します。

適用対象

こちらもご覧ください