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

Dim instance As MenuItemCollection Dim value As MenuItem Dim returnValue As Integer returnValue = instance.IndexOf(value)
戻り値
現在の MenuItemCollection 内で value が見つかった場合は、最初に見つかった位置の 0 から始まるインデックス番号。それ以外の場合は -1。

IndexOf メソッドを使用して、現在の MenuItemCollection オブジェクト内の指定した MenuItem オブジェクトのインデックスを確認します。メニュー項目がコレクション内にない場合、このメソッドは -1 を返します。
![]() |
---|

IndexOf メソッドを使用して、MenuItemCollection オブジェクト内の MenuItem オブジェクトのインデックスを確認する方法のコード例を次に示します。
<%@ Page Language="VB" %> <script runat="server"> Sub NavigationMenu_MenuItemClick(ByVal sender As Object, ByVal e As MenuEventArgs) ' Retrieve the parent menu item of the selected menu item. Dim parent As MenuItem = e.Item.Parent ' Determine whether the selected menu item is a ' root menu item. Root menu items are stored in ' a Menu control's Items collection. Other menu ' items are stored in the parent menu item's ' ChildItems collection. If parent IsNot Nothing Then Message.Text = "The " & e.Item.Text & _ " menu item has an index of " & _ parent.ChildItems.IndexOf(e.Item).ToString() & _ " in the parent menu item's ChildItems collection." Else Message.Text = "The " & e.Item.Text & _ " menu item has an index of " & _ NavigationMenu.Items.IndexOf(e.Item).ToString() & _ " in the Menu control's Items collection." End If End Sub </script> <html> <body> <form runat="server"> <h3>MenuItemCollection IndexOf 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) { // Retrieve the parent menu item of the selected menu item. MenuItem parent = e.Item.Parent; // Determine whether the selected menu item is a // root menu item. Root menu items are stored in // a Menu control's Items collection. Other menu // items are stored in the parent menu item's // ChildItems collection. if (parent != null) { Message.Text = "The " + e.Item.Text + " menu item has an index of " + parent.ChildItems.IndexOf(e.Item).ToString() + " in the parent menu item's ChildItems collection."; } else { Message.Text = "The " + e.Item.Text + " menu item has an index of " + NavigationMenu.Items.IndexOf(e.Item).ToString() + " in the Menu control's Items collection."; } } </script> <html> <body> <form runat="server"> <h3>MenuItemCollection IndexOf 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.IndexOf メソッドを検索する場合は、下記のリンクをクリックしてください。

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