ControlCollection クラス

定義

ASP.NET サーバー コントロールが子コントロールのリストを維持できるようにする、コレクション コンテナーを提供します。

public ref class ControlCollection : System::Collections::ICollection
public class ControlCollection : System.Collections.ICollection
type ControlCollection = class
    interface ICollection
    interface IEnumerable
Public Class ControlCollection
Implements ICollection
継承
ControlCollection
派生
実装

次のコード例では、 メソッドをControl.CreateChildControlsオーバーライドして、 という名前のカスタム クラスの両方のインスタンス (という名前ChildControlMessageの文字列プロパティを持つ) の 2 つのコントロールを作成します。 作成すると、2 つのコントロールが に ControlCollection追加されます。 メソッドは Add 、これらの各コントロールで呼び出され、このバージョンの Control.CreateChildControlsを含むクラスに追加されます。 ChildControlsCreatedこれらのコントロールが不必要に再び作成されないように、 プロパティは にtrue設定されます。


protected override void CreateChildControls()
{               
   // Creates a new ControlCollection. 
   this.CreateControlCollection();

   // Create child controls.
    ChildControl firstControl = new ChildControl();
   firstControl.Message = "FirstChildControl";

   ChildControl secondControl = new ChildControl();
   secondControl.Message = "SecondChildControl";
   
   Controls.Add(firstControl);
   Controls.Add(secondControl);

   // Prevent child controls from being created again.
   ChildControlsCreated = true;
}

Protected Overrides Sub CreateChildControls()
   ' Creates a new ControlCollection. 
   Me.CreateControlCollection()
   
   ' Create child controls.
   Dim firstControl As New ChildControl()
   firstControl.Message = "FirstChildControl"
   
   Dim secondControl As New ChildControl()
   secondControl.Message = "SecondChildControl"
   
   Controls.Add(firstControl)
   Controls.Add(secondControl)
   
   ' Prevent child controls from being created again.
   ChildControlsCreated = True
End Sub


注釈

クラスのプロパティとメソッドには、 プロパティを ControlCollection 使用して Control.Controls アクセスできます。 Controlクラスはすべての ASP.NET サーバー コントロールの基本クラスであるため、すべてのサーバー コントロールはこのプロパティを継承します。

コレクションの詳細については、「 コレクションとデータ構造」を参照してください。

コンストラクター

ControlCollection(Control)

指定した親サーバー コントロールの ControlCollection クラスの新しいインスタンスを初期化します。

プロパティ

Count

指定された ASP.NET サーバー コントロールの ControlCollection オブジェクト内にあるサーバー コントロールの数を取得します。

IsReadOnly

ControlCollection オブジェクトが読み取り専用かどうかを示す値を取得します。

IsSynchronized

ControlCollection オブジェクトが同期されているかどうかを示す値を取得します。

Item[Int32]

ControlCollection オブジェクトの指定されたインデックス位置にあるサーバー コントロールへの参照を取得します。

Owner

ControlCollection オブジェクトが属する ASP.NET サーバー コントロールを取得します。

SyncRoot

コントロールのコレクションへのアクセスを同期するために使用するオブジェクトを取得します。

メソッド

Add(Control)

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

AddAt(Int32, Control)

指定したインデックス位置に、指定した Control オブジェクトを追加します。

Clear()

現在のサーバー コントロールの ControlCollection オブジェクトからすべてのコントロールを削除します。

Contains(Control)

指定したサーバー コントロールが親サーバー コントロールの ControlCollection オブジェクト内にあるかどうかを確認します。

CopyTo(Array, Int32)

ControlCollection オブジェクトに格納されている子コントロールを、Array オブジェクトに、Array 内の指定したインデックス位置からコピーします。

Equals(Object)

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

(継承元 Object)
GetEnumerator()

ControlCollection オブジェクトを繰り返し処理できる列挙子を取得します。

GetHashCode()

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

(継承元 Object)
GetType()

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

(継承元 Object)
IndexOf(Control)

コレクション内の指定した Control オブジェクトのインデックスを取得します。

MemberwiseClone()

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

(継承元 Object)
Remove(Control)

親サーバー コントロールの ControlCollection オブジェクトから、指定したサーバー コントロールを削除します。

RemoveAt(Int32)

ControlCollection オブジェクトから、指定したインデックス位置にある子コントロールを削除します。

ToString()

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

(継承元 Object)

拡張メソッド

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

IEnumerableIQueryable に変換します。

適用対象

こちらもご覧ください