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

ViewCollection クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

MultiView コントロールが子コントロールの一覧を維持するためのコレクション コンテナを表します。

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

Public Class ViewCollection
    Inherits ControlCollection
Dim instance As ViewCollection
public class ViewCollection : ControlCollection
public ref class ViewCollection : public
 ControlCollection
public class ViewCollection extends ControlCollection
public class ViewCollection extends
 ControlCollection
解説解説
使用例使用例

View コントロールを、プログラムによって MultiView コントロールに追加する方法のコード例を次に示します。各 View コントロールが作成された後で AddAt メソッドを使用して、View コントロールを MultiView コントロールの指定したインデックスにある ViewCollection コレクションに追加します。Item インデクサを使用して、ViewCollection コレクション内に格納されている View コントロールの ID プロパティにアクセスし、そのプロパティをユーザーに表示します。

<%@ Page Language="VB"%>
<html>
<head>

    <script runat="server">
      
        Sub Button1_Click(ByVal Sender As
 Object, ByVal e As EventArgs)
            ' Create a MultiView control.
            Dim MultiView1 As New
 MultiView

            ' Create a ViewCollection for the View 
            ' controls contained in MultiView1.
            Dim myViewCollection As New
 ViewCollection(MultiView1)

            ' Create a View control. 
            Dim View1 As New
 View
            ' Use a helper function to create the view.
            View1 = CreateView("View1")
            ' Add View1 to myViewCollection at index 0.
            myViewCollection.AddAt(0, View1)

            ' Create a second View control and 
            ' add it to myViewCollection at index 1.
            Dim View2 As New
 View
            View2 = CreateView("View2")
            myViewCollection.AddAt(1, View2)

            ' Create a third View control and 
            ' add it to myViewCollection at index 0.
            ' Inserting View3 at index 0 
            ' causes View1 to move to index 1  
            ' and View2 to move to index 2.
            Dim View3 As New
 View
            View3 = CreateView("View3")
            myViewCollection.AddAt(0, View3)

            ' Show the contents of myViewCollection on the page.
            DisplayViewCollectionContents(myViewCollection)
            
        End Sub

        ' A function to programmatically create a View control.
        Private Function CreateView(ByVal
 viewId As String) As View
            ' Create a View control
            Dim myView As New
 View
            myView.ID = viewId

            ' Create a Panel control.
            Dim Panel1 As New
 Panel

            ' Set the style properties for Panel1.
            Panel1.Height = New Unit(150)
            Panel1.Width = New Unit(150)
            Panel1.BackColor = System.Drawing.Color.Azure
            Panel1.BorderStyle = BorderStyle.Double

            ' Add Panel1 to the Controls collection
            ' of the View control.
            myView.Controls.Add(Panel1)

            ' Create a Label control.
            Dim Label1 As New
 Label

            ' Set the properties for Label1.
            Label1.Text = "This is " + CStr(myView.ID)

            ' Add Label1 to the Controls collection
            ' of the Panel1 control.
            Panel1.Controls.Add(Label1)

            Return myView
        End Function

        ' A sub-routine to display the contents of myViewCollection.
        Sub DisplayViewCollectionContents(ByVal
 collection As ViewCollection)
            ' Use the Item property to access the ID of the View
            ' control at the specified index in the collection.
            Label1.Text = "The view at index 0 is "
 + collection.Item(0).ID
            Label2.Text = "The view at index 1 is "
 + collection.Item(1).ID
            Label3.Text = "The view at index 2 is "
 + collection.Item(2).ID
        End Sub

</script>
 
</head>
<body>

    <form ID="Form1" runat="server">

        <h3>ViewCollection example</h3> 

        <asp:Button id="Button2" 
            Text="Show ViewCollection contents" 
            OnClick="Button1_Click" 
            runat="Server"/>
        </asp:Button><br><br>  
        
        <hr>
  
        <asp:Label ID=Label1
            runat="Server">
        </asp:Label><br><br> 

        <asp:Label ID="Label2"
            runat="Server">
        </asp:Label><br><br>

        <asp:Label ID="Label3"
            runat="Server">
        </asp:Label><br><br> 
       
    </form>
   
</body>
</html>
.NET Framework のセキュリティ.NET Framework のセキュリティ
継承階層継承階層
System.Object
   System.Web.UI.ControlCollection
    System.Web.UI.WebControls.ViewCollection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ViewCollection コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

ViewCollection クラスの新しいインスタンスを初期化します。

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

使用例使用例

View コントロールを、プログラムによって MultiView コントロールに追加する方法のコード例を次に示します。各 View コントロールが作成された後で AddAt メソッドを使用して、View コントロールを MultiView コントロールの指定したインデックスにある ViewCollection コレクションに追加します。Item インデクサを使用して、ViewCollection コレクション内に格納されている View コントロールの ID プロパティにアクセスし、そのプロパティをユーザーに表示します。

<%@ Page Language="VB"%>
<html>
<head>

    <script runat="server">
      
        Sub Button1_Click(ByVal Sender As
 Object, ByVal e As EventArgs)
            ' Create a MultiView control.
            Dim MultiView1 As New
 MultiView

            ' Create a ViewCollection for the View 
            ' controls contained in MultiView1.
            Dim myViewCollection As New
 ViewCollection(MultiView1)

            ' Create a View control. 
            Dim View1 As New
 View
            ' Use a helper function to create the view.
            View1 = CreateView("View1")
            ' Add View1 to myViewCollection at index 0.
            myViewCollection.AddAt(0, View1)

            ' Create a second View control and 
            ' add it to myViewCollection at index 1.
            Dim View2 As New
 View
            View2 = CreateView("View2")
            myViewCollection.AddAt(1, View2)

            ' Create a third View control and 
            ' add it to myViewCollection at index 0.
            ' Inserting View3 at index 0 
            ' causes View1 to move to index 1  
            ' and View2 to move to index 2.
            Dim View3 As New
 View
            View3 = CreateView("View3")
            myViewCollection.AddAt(0, View3)

            ' Show the contents of myViewCollection on the page.
            DisplayViewCollectionContents(myViewCollection)
            
        End Sub

        ' A function to programmatically create a View control.
        Private Function CreateView(ByVal
 viewId As String) As View
            ' Create a View control
            Dim myView As New
 View
            myView.ID = viewId

            ' Create a Panel control.
            Dim Panel1 As New
 Panel

            ' Set the style properties for Panel1.
            Panel1.Height = New Unit(150)
            Panel1.Width = New Unit(150)
            Panel1.BackColor = System.Drawing.Color.Azure
            Panel1.BorderStyle = BorderStyle.Double

            ' Add Panel1 to the Controls collection
            ' of the View control.
            myView.Controls.Add(Panel1)

            ' Create a Label control.
            Dim Label1 As New
 Label

            ' Set the properties for Label1.
            Label1.Text = "This is " + CStr(myView.ID)

            ' Add Label1 to the Controls collection
            ' of the Panel1 control.
            Panel1.Controls.Add(Label1)

            Return myView
        End Function

        ' A sub-routine to display the contents of myViewCollection.
        Sub DisplayViewCollectionContents(ByVal
 collection As ViewCollection)
            ' Use the Item property to access the ID of the View
            ' control at the specified index in the collection.
            Label1.Text = "The view at index 0 is "
 + collection.Item(0).ID
            Label2.Text = "The view at index 1 is "
 + collection.Item(1).ID
            Label3.Text = "The view at index 2 is "
 + collection.Item(2).ID
        End Sub

</script>
 
</head>
<body>

    <form ID="Form1" runat="server">

        <h3>ViewCollection example</h3> 

        <asp:Button id="Button2" 
            Text="Show ViewCollection contents" 
            OnClick="Button1_Click" 
            runat="Server"/>
        </asp:Button><br><br>  
        
        <hr>
  
        <asp:Label ID=Label1
            runat="Server">
        </asp:Label><br><br> 

        <asp:Label ID="Label2"
            runat="Server">
        </asp:Label><br><br>

        <asp:Label ID="Label3"
            runat="Server">
        </asp:Label><br><br> 
       
    </form>
   
</body>
</html>
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
ViewCollection クラス
ViewCollection メンバ
System.Web.UI.WebControls 名前空間
MultiView クラス

ViewCollection プロパティ


パブリック プロパティパブリック プロパティ

( プロテクト プロパティ も参照)
  名前 説明
パブリック プロパティ Count  指定された ASP.NET サーバー コントロールの ControlCollection オブジェクト内にあるサーバー コントロールの数を取得します。 ( ControlCollection から継承されます。)
パブリック プロパティ IsReadOnly  ControlCollection オブジェクトが読み取り専用かどうかを示す値を取得します。 ( ControlCollection から継承されます。)
パブリック プロパティ IsSynchronized  ControlCollection オブジェクトの同期がとられているかどうかを示す値を取得します。 ( ControlCollection から継承されます。)
パブリック プロパティ Item ViewCollection コレクション内の指定したインデックス位置の View コントロールへの参照を取得します。
パブリック プロパティ SyncRoot  コントロールのコレクションへのアクセスを同期するために使用するオブジェクトを取得します。 ( ControlCollection から継承されます。)
プロテクト プロパティプロテクト プロパティ
  名前 説明
プロテクト プロパティ Owner  ControlCollection オブジェクトが属する ASP.NET サーバー コントロールを取得します。 ( ControlCollection から継承されます。)
参照参照

関連項目

ViewCollection クラス
System.Web.UI.WebControls 名前空間
MultiView クラス
MultiView.Views プロパティ
View クラス

その他の技術情報

MultiView Web サーバー コントロールおよび View Web サーバー コントロール

ViewCollection メソッド


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

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

関連項目

ViewCollection クラス
System.Web.UI.WebControls 名前空間
MultiView クラス
MultiView.Views プロパティ
View クラス

その他の技術情報

MultiView Web サーバー コントロールおよび View Web サーバー コントロール

ViewCollection メンバ

MultiView コントロールが子コントロールの一覧を維持するためのコレクション コンテナを表します。

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


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

関連項目

ViewCollection クラス
System.Web.UI.WebControls 名前空間
MultiView クラス
MultiView.Views プロパティ
View クラス

その他の技術情報

MultiView Web サーバー コントロールおよび View Web サーバー コントロール


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

英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「ViewCollection」の関連用語

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

   

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



ViewCollectionのページの著作権

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

©2026 GRAS Group, Inc.RSS