MenuItemCollection.IndexOf メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > MenuItemCollection.IndexOf メソッドの意味・解説 

MenuItemCollection.IndexOf メソッド

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

コレクション内の指定した MenuItem オブジェクトインデックス確認します

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

Public Function IndexOf ( _
    value As MenuItem _
) As Integer
Dim instance As MenuItemCollection
Dim value As MenuItem
Dim returnValue As Integer

returnValue = instance.IndexOf(value)
public int IndexOf (
    MenuItem value
)
public:
int IndexOf (
    MenuItem^ value
)
public int IndexOf (
    MenuItem value
)
public function IndexOf (
    value : MenuItem
) : int

パラメータ

value

検索する MenuItem。

戻り値
現在の MenuItemCollection 内で value見つかった場合は、最初に見つかった位置の 0 から始まるインデックス番号それ以外場合は -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>

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MenuItemCollection クラス
MenuItemCollection メンバ
System.Web.UI.WebControls 名前空間
Menu クラス
MenuItem クラス
Menu.Items プロパティ
MenuItem.ChildItems プロパティ
Count
Contains


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

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

辞書ショートカット

すべての辞書の索引

MenuItemCollection.IndexOf メソッドのお隣キーワード
検索ランキング

   

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



MenuItemCollection.IndexOf メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS