MenuItemCollection クラス
アセンブリ: System.Web (system.web.dll 内)


MenuItemCollection クラスは、Menu コントロールに存在する MenuItem オブジェクトのコレクションを格納および管理する場合に使用されます。Menu コントロールは MenuItemCollection クラスを使用して、ルート メニュー項目を Items プロパティに格納します。このコレクションは、メニュー項目のサブメニュー項目がある場合、それらを格納するために MenuItem オブジェクトの ChildItems プロパティでも使用されます。
MenuItemCollection クラスは、コレクション内の項目にアクセスするための複数の方法をサポートしています。
MenuItem オブジェクトを追加および削除することにより、MenuItemCollection オブジェクトをプログラムによって管理できます。コレクションにメニュー項目を追加するには、Add メソッドまたは AddAt メソッドを使用します。コレクションからノードを削除するには、Remove、RemoveAt、または Clear の各メソッドを使用します。
![]() |
---|
Menu コントロールがデータ ソースにバインドされると、Items コレクションと ChildItems コレクションはバインディングが発生するたびに自動的に設定されます。バインディングとバインディングの間にコレクションに加えられた変更は、すべて失われます。これらの変更を保持するには、データ ソースを更新するか、バインドのたびにコレクションを手動でビルドし直します。 |
MenuItemCollection クラスには、コレクション自体の情報を取得できるプロパティとメソッドが格納されています。コレクション内の項目数を確認するには、Count プロパティを使用します。コレクションに特定の MenuItem オブジェクトが含まれているかどうかを確認する場合は、Contains メソッドを使用します。コレクション内の MenuItem オブジェクトのインデックスを取得するには、IndexOf メソッドを使用します。

宣言構文を使用して、Items コレクションと ChildItems コレクションを設定する方法のコード例を次に示します。
<%@ Page Language="VB" %> <html> <!-- For the hover styles of the Menu control to --> <!-- work correctly, you must include this head --> <!-- element. --> <head runat="server"> </head> <body> <form runat="server"> <h3>Menu Declarative Example</h3> <!-- Use declarative syntax to create the --> <!-- menu structure. Submenu items are --> <!-- created by nesting them in parent menu --> <!-- items. --> <asp:menu id="NavigationMenu" disappearafter="2000" staticdisplaylevels="2" staticsubmenuindent="10" orientation="Vertical" font-names="Arial" target="_blank" runat="server"> <staticmenuitemstyle backcolor="LightSteelBlue" forecolor="Black"/> <statichoverstyle backcolor="LightSkyBlue"/> <dynamicmenuitemstyle backcolor="Black" forecolor="Silver"/> <dynamichoverstyle backcolor="LightSkyBlue" forecolor="Black"/> <items> <asp:menuitem navigateurl="Home.aspx" text="Home" tooltip="Home"> <asp:menuitem navigateurl="Music.aspx" text="Music" tooltip="Music"> <asp:menuitem navigateurl="Classical.aspx" text="Classical" tooltip="Classical"/> <asp:menuitem navigateurl="Rock.aspx" text="Rock" tooltip="Rock"/> <asp:menuitem navigateurl="Jazz.aspx" text="Jazz" tooltip="Jazz"/> </asp:menuitem> <asp:menuitem navigateurl="Movies.aspx" text="Movies" tooltip="Movies"> <asp:menuitem navigateurl="Action.aspx" text="Action" tooltip="Action"/> <asp:menuitem navigateurl="Drama.aspx" text="Drama" tooltip="Drama"/> <asp:menuitem navigateurl="Musical.aspx" text="Musical" tooltip="Musical"/> </asp:menuitem> </asp:menuitem> </items> </asp:menu> </form> </body> </html>
<%@ Page Language="C#" %> <html> <!-- For the hover styles of the Menu control to --> <!-- work correctly, you must include this head --> <!-- element. --> <head runat="server"> </head> <body> <form runat="server"> <h3>Menu Declarative Example</h3> <!-- Use declarative syntax to create the --> <!-- menu structure. Submenu items are --> <!-- created by nesting them in parent menu --> <!-- items. --> <asp:menu id="NavigationMenu" disappearafter="2000" staticdisplaylevels="2" staticsubmenuindent="10" orientation="Vertical" font-names="Arial" target="_blank" runat="server"> <staticmenuitemstyle backcolor="LightSteelBlue" forecolor="Black"/> <statichoverstyle backcolor="LightSkyBlue"/> <dynamicmenuitemstyle backcolor="Black" forecolor="Silver"/> <dynamichoverstyle backcolor="LightSkyBlue" forecolor="Black"/> <items> <asp:menuitem navigateurl="Home.aspx" text="Home" tooltip="Home"> <asp:menuitem navigateurl="Music.aspx" text="Music" tooltip="Music"> <asp:menuitem navigateurl="Classical.aspx" text="Classical" tooltip="Classical"/> <asp:menuitem navigateurl="Rock.aspx" text="Rock" tooltip="Rock"/> <asp:menuitem navigateurl="Jazz.aspx" text="Jazz" tooltip="Jazz"/> </asp:menuitem> <asp:menuitem navigateurl="Movies.aspx" text="Movies" tooltip="Movies"> <asp:menuitem navigateurl="Action.aspx" text="Action" tooltip="Action"/> <asp:menuitem navigateurl="Drama.aspx" text="Drama" tooltip="Drama"/> <asp:menuitem navigateurl="Musical.aspx" text="Musical" tooltip="Musical"/> </asp:menuitem> </asp:menuitem> </items> </asp:menu> </form> </body> </html>
MenuItem オブジェクトをルート メニュー項目の ChildItems コレクションに、プログラムによって追加する方法のコード例を次に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Not IsPostBack Then ' Retrieve the root menu item from the Items ' collection of the Menu control using the indexer. Dim homeMenuItem As MenuItem = NavigationMenu.Items(0) ' Create the submenu item. Dim newSubMenuItem = New MenuItem("New Category") ' Add the submenu item to the ChildItems ' collection of the root menu item. homeMenuItem.ChildItems.Add(newSubMenuItem) End If End Sub </script> <html> <body> <form runat="server"> <h3>MenuItemCollection Add Example</h3> <asp:menu id="NavigationMenu" orientation="Vertical" target="_blank" runat="server"> <items> <asp:menuitem text="Home" tooltip="Home"> <asp:menuitem text="Music" tooltip="Music"> <asp:menuitem text="Classical" tooltip="Classical"/> <asp:menuitem text="Rock" tooltip="Rock"/> <asp:menuitem text="Jazz" tooltip="Jazz"/> </asp:menuitem> <asp:menuitem text="Movies" tooltip="Movies"> <asp:menuitem text="Action" tooltip="Action"/> <asp:menuitem text="Drama" tooltip="Drama"/> <asp:menuitem text="Musical" tooltip="Musical"/> </asp:menuitem> </asp:menuitem> </items> </asp:menu> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void Page_Load(Object sender, EventArgs e) { if (!IsPostBack) { // Retrieve the root menu item from the Items // collection of the Menu control using the indexer. MenuItem homeMenuItem = NavigationMenu.Items[0]; // Create the submenu item. MenuItem newSubMenuItem = new MenuItem("New Category"); // Add the submenu item to the ChildItems // collection of the root menu item. homeMenuItem.ChildItems.Add(newSubMenuItem); } } </script> <html> <body> <form runat="server"> <h3>MenuItemCollection Add Example</h3> <asp:menu id="NavigationMenu" orientation="Vertical" target="_blank" runat="server"> <items> <asp:menuitem text="Home" tooltip="Home"> <asp:menuitem text="Music" tooltip="Music"> <asp:menuitem text="Classical" tooltip="Classical"/> <asp:menuitem text="Rock" tooltip="Rock"/> <asp:menuitem text="Jazz" tooltip="Jazz"/> </asp:menuitem> <asp:menuitem text="Movies" tooltip="Movies"> <asp:menuitem text="Action" tooltip="Action"/> <asp:menuitem text="Drama" tooltip="Drama"/> <asp:menuitem text="Musical" tooltip="Musical"/> </asp:menuitem> </asp:menuitem> </items> </asp:menu> </form> </body> </html>


System.Web.UI.WebControls.MenuItemCollection


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


MenuItemCollection コンストラクタ ()
アセンブリ: System.Web (system.web.dll 内)


既定値を使用して MenuItemCollection クラスの新しいインスタンスを初期化するには、このコンストラクタを使用します。通常このコンストラクタは、親メニュー (または所有者) を必要としないルート メニュー項目のコレクションを作成する場合に使用します。
![]() |
---|
子メニュー項目のコレクションを作成するときは、このコンストラクタではなく、owner パラメータを受け取るオーバーロードされたコンストラクタを使用して、親メニュー項目を指定します。 |
このコンストラクタは、主にコントロールの開発者が Menu コントロールを拡張して Items プロパティを初期化する場合に使用します。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


MenuItemCollection コンストラクタ

名前 | 説明 |
---|---|
MenuItemCollection () | 既定値を使用して、MenuItemCollection クラスの新しいインスタンスを初期化します。 |
MenuItemCollection (MenuItem) | 親メニュー項目 (または所有者) を指定して、MenuItemCollection クラスの新しいインスタンスを初期化します。 |

MenuItemCollection コンストラクタ (MenuItem)
アセンブリ: System.Web (system.web.dll 内)


親メニュー項目 (または所有者) を指定して MenuItemCollection クラスの新しいインスタンスを初期化するには、このコンストラクタを使用します。通常このコンストラクタは、親メニュー項目を指定する必要のある子メニュー項目のコレクションを作成する場合に使用します。
![]() |
---|
ルート メニュー項目には親メニュー項目がないため、ルート メニュー項目のコレクションを作成するときは、既定のコンストラクタを使用してください。 |
このコンストラクタは、主にコントロールの開発者が MenuItem クラスを拡張して ChildItems プロパティを初期化する場合に使用します。

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


MenuItemCollection プロパティ

名前 | 説明 | |
---|---|---|
![]() | Count | 現在の MenuItemCollection オブジェクト内のメニュー項目の数を取得します。 |
![]() | IsSynchronized | MenuItemCollection オブジェクトへのアクセスが同期されている (スレッド セーフである) かどうかを示す値を取得します。 |
![]() | Item | 現在の MenuItemCollection オブジェクト内の指定したインデックス位置にある MenuItem オブジェクトを取得します。 |
![]() | SyncRoot | MenuItemCollection オブジェクトへのアクセスを同期するために使用できるオブジェクトを取得します。 |

名前 | 説明 | |
---|---|---|
![]() | System.Web.UI.IStateManager.IsTrackingViewState | MenuItemCollection オブジェクトがビューステートへの変更を保存しているかどうかを示す値を取得します。 |

MenuItemCollection メソッド

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

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Web.UI.IStateManager.LoadViewState | MenuItemCollection オブジェクトが前回保存したビューステートを読み込みます。 |
![]() | System.Web.UI.IStateManager.SaveViewState | ビューステートへの変更を Object に保存します。 |
![]() | System.Web.UI.IStateManager.TrackViewState | ビューステートへの変更を追跡するように MenuItemCollection オブジェクトに指示します。 |

MenuItemCollection メンバ
Menu コントロール内のメニュー項目のコレクションを表します。このクラスは継承できません。
MenuItemCollection データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Count | 現在の MenuItemCollection オブジェクト内のメニュー項目の数を取得します。 |
![]() | IsSynchronized | MenuItemCollection オブジェクトへのアクセスが同期されている (スレッド セーフである) かどうかを示す値を取得します。 |
![]() | Item | 現在の MenuItemCollection オブジェクト内の指定したインデックス位置にある MenuItem オブジェクトを取得します。 |
![]() | SyncRoot | MenuItemCollection オブジェクトへのアクセスを同期するために使用できるオブジェクトを取得します。 |

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

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | System.Web.UI.IStateManager.LoadViewState | MenuItemCollection オブジェクトが前回保存したビューステートを読み込みます。 |
![]() | System.Web.UI.IStateManager.SaveViewState | ビューステートへの変更を Object に保存します。 |
![]() | System.Web.UI.IStateManager.TrackViewState | ビューステートへの変更を追跡するように MenuItemCollection オブジェクトに指示します。 |
![]() | System.Web.UI.IStateManager.IsTrackingViewState | MenuItemCollection オブジェクトがビューステートへの変更を保存しているかどうかを示す値を取得します。 |

Weblioに収録されているすべての辞書からMenuItemCollectionを検索する場合は、下記のリンクをクリックしてください。

- MenuItemCollectionのページへのリンク