MenuItemCollection.Contains メソッド
アセンブリ: System.Web (system.web.dll 内)

Dim instance As MenuItemCollection Dim c As MenuItem Dim returnValue As Boolean returnValue = instance.Contains(c)
戻り値
指定した MenuItem オブジェクトがコレクションに格納されている場合は true。それ以外の場合は false。

Contains メソッドを使用して、MenuItem オブジェクトが現在の MenuItemCollection オブジェクトに格納されているかどうかを確認します。通常このメソッドは、メニュー項目のコレクションへの追加やコレクションからの削除などのタスクを実行する前に、MenuItem オブジェクトが存在しているかどうかを確認するために使用します。

Contains メソッドを使用して、MenuItem オブジェクトが MenuItemCollection オブジェクトに格納されているかどうかを確認する方法のコード例を次に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub NavigationMenu_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs) ' Use the Contains method to determine whether the menu ' item selected by the user is contained in the Items ' collection of the Menu control. If NavigationMenu.Items.Contains(e.Item) Then Message.Text = "You selected the root menu item." Else Message.Text = "You selected a submenu item." End If End Sub </script> <html> <body> <form runat="server"> <h3>MenuItemCollection Contains Example</h3> Select an item from the menu. <br/><br/> <asp:menu id="NavigationMenu" orientation="Vertical" target="_blank" onmenuitemclick="NavigationMenu_MenuItemClick" 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> <hr/> <asp:label id="Message" runat="server"/> </form> </body> </html>
<%@ Page Language="C#" %> <script runat="server"> void NavigationMenu_MenuItemClick(Object sender, MenuEventArgs e) { // Use the Contains method to determine whether the menu // item selected by the user is contained in the Items // collection of the Menu control. if(NavigationMenu.Items.Contains(e.Item)) { Message.Text = "You selected the root menu item."; } else { Message.Text = "You selected a submenu item."; } } </script> <html> <body> <form runat="server"> <h3>MenuItemCollection Contains Example</h3> Select an item from the menu. <br/><br/> <asp:menu id="NavigationMenu" orientation="Vertical" target="_blank" onmenuitemclick="NavigationMenu_MenuItemClick" 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> <hr/> <asp:label id="Message" runat="server"/> </form> </body> </html>

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


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

- MenuItemCollection.Contains メソッドのページへのリンク