ControlCollectionとは? わかりやすく解説

ControlCollection クラス

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

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Class ControlCollection
    Implements ICollection, IEnumerable
Dim instance As ControlCollection
public class ControlCollection : ICollection,
 IEnumerable
public ref class ControlCollection : ICollection,
 IEnumerable
public class ControlCollection implements ICollection,
 IEnumerable
public class ControlCollection implements ICollection,
 IEnumerable
解説解説
使用例使用例

Control.CreateChildControls メソッドオーバーライドして、2 つコントロール (ChildControl という名前のカスタム クラス2 つインスタンス) を作成するコード例次に示します。これらのコントロールには、Message という名前の文字列プロパティ存在します2 つコントロールを、作成した後で ControlCollection追加してます。このバージョンControl.CreateChildControls を含むクラスにこれらのコントロール追加するために、Add メソッドを各コントロールに対して呼び出してます。このコードではまた、作成したコントロール不必要に再作成されることのないよう、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 'CreateChildControls


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;
}

継承階層継承階層
System.Object
  System.Web.UI.ControlCollection
     派生クラス
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ControlCollection コンストラクタ

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

名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文構文

例外例外
例外種類条件

ArgumentException

owner パラメータnull 参照 (Visual Basic では Nothing) である場合発生します

使用例使用例

次に示すのは、ControlCollection クラスコンストラクタオーバーライドするカスタム クラスコード例です。このカスタム クラスでは、コレクションインスタンス作成されるトレース ログメッセージ (Owner プロパティの名前を含む) が書き込まれます。この例を使用するには、ページまたはアプリケーショントレース機能有効になっている必要があります

' Create a custom ControlCollection that writes
' information to the Trace log when an instance
' of the collection is created.
<AspNetHostingPermission(SecurityAction.Demand, _
   Level:=AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class
 CustomControlCollection
    Inherits ControlCollection

    Private context As HttpContext

    Public Sub New(ByVal
 owner As Control)
        MyBase.New(owner)
        HttpContext.Current.Trace.Write("The control collection
 is created.")
        ' Display the Name of the control
        ' that uses this collection when tracing is enabled.
        HttpContext.Current.Trace.Write("The owner is: "
 _
      & Me.Owner.ToString())
    End Sub


End Class

// Create a custom ControlCollection that writes
// information to the Trace log when an instance
// of the collection is created.
[AspNetHostingPermission(SecurityAction.Demand, Level=AspNetHostingPermissionLevel.Minimal)]
public class CustomControlCollection : ControlCollection
{
    private HttpContext context;

    public CustomControlCollection(Control owner)
        : base(owner)
    {

        HttpContext.Current.Trace.Write("The control collection is created.");
        // Display the Name of the control
        // that uses this collection when tracing is enabled.
        HttpContext.Current.Trace.Write("The owner is: " + this.Owner.ToString());
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ControlCollection クラス
ControlCollection メンバ
System.Web.UI 名前空間
Control.Controls プロパティ
Control クラス

ControlCollection プロパティ


ControlCollection メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Add 指定した Control オブジェクトコレクション追加します
パブリック メソッド AddAt 指定したインデックス位置に、指定した Control オブジェクト追加します
パブリック メソッド Clear 現在のサーバー コントロールの ControlCollection オブジェクトからすべてのコントロール削除します
パブリック メソッド Contains 指定したサーバー コントロールが親サーバー コントロールControlCollection オブジェクト内にあるかどうか確認します
パブリック メソッド CopyTo ControlCollection オブジェクト格納されている子コントロールを、System.Array オブジェクトに、System.Array 内の指定したインデックス位置からコピーします
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 ( Object から継承されます。)
パブリック メソッド GetEnumerator ControlCollection オブジェクト反復処理できる列挙子を取得します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 ( Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド IndexOf コレクション内の指定した Control オブジェクトインデックス取得します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド Remove サーバー コントロールControlCollection オブジェクトから、指定したサーバー コントロール削除します
パブリック メソッド RemoveAt ControlCollection オブジェクトから、指定したインデックス位置にある子コントロール削除します
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ControlCollection クラス
System.Web.UI 名前空間
Control クラス
Page
Control.Controls プロパティ

その他の技術情報

コレクションデータ構造

ControlCollection メンバ

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

ControlCollection データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
パブリック プロパティパブリック プロパティ
プロテクト プロパティプロテクト プロパティ
パブリック メソッドパブリック メソッド
( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Add 指定した Control オブジェクトコレクション追加します
パブリック メソッド AddAt 指定したインデックス位置に、指定した Control オブジェクト追加します
パブリック メソッド Clear 現在のサーバー コントロールControlCollection オブジェクトからすべてのコントロール削除します
パブリック メソッド Contains 指定したサーバー コントロールが親サーバー コントロールControlCollection オブジェクト内にあるかどうか確認します
パブリック メソッド CopyTo ControlCollection オブジェクト格納されている子コントロールを、System.Array オブジェクトに、System.Array 内の指定したインデックス位置からコピーします
パブリック メソッド Equals  オーバーロードされます2 つObject インスタンス等しかどうか判断します。 (Object から継承されます。)
パブリック メソッド GetEnumerator ControlCollection オブジェクト反復処理できる列挙子を取得します
パブリック メソッド GetHashCode  特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用適してます。 (Object から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド IndexOf コレクション内の指定した Control オブジェクトインデックス取得します
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド Remove サーバー コントロールControlCollection オブジェクトから、指定したサーバー コントロール削除します
パブリック メソッド RemoveAt ControlCollection オブジェクトから、指定したインデックス位置にある子コントロール削除します
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

ControlCollection クラス
System.Web.UI 名前空間
Control クラス
Page
Control.Controls プロパティ

その他の技術情報

コレクションデータ構造


このページでは「.NET Framework クラス ライブラリ リファレンス」からControlCollectionを検索した結果を表示しています。
Weblioに収録されているすべての辞書からControlCollectionを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からControlCollection を検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ControlCollection」の関連用語

ControlCollectionのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ControlCollectionのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS