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

MenuItemCollection クラス

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

Menu コントロール内のメニュー項目のコレクション表します。このクラス継承できません。

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

Public NotInheritable Class
 MenuItemCollection
    Implements ICollection, IEnumerable, IStateManager
Dim instance As MenuItemCollection
public sealed class MenuItemCollection : ICollection,
 IEnumerable, IStateManager
public ref class MenuItemCollection sealed
 : ICollection, IEnumerable, IStateManager
public final class MenuItemCollection implements
 ICollection, IEnumerable, 
    IStateManager
public final class MenuItemCollection implements
 ICollection, IEnumerable, 
    IStateManager
解説解説

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>

.NET Framework のセキュリティ.NET Frameworkセキュリティ
継承階層継承階層
System.Object
  System.Web.UI.WebControls.MenuItemCollection
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MenuItemCollection メンバ
System.Web.UI.WebControls 名前空間
Menu クラス
MenuItem クラス
Menu.Items プロパティ
MenuItem.ChildItems プロパティ
Count
Add
AddAt
Clear
Contains
CopyTo
CopyTo
GetEnumerator
IndexOf
Item
RemoveAt

MenuItemCollection コンストラクタ ()

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

既定値使用して、MenuItemCollection クラス新しインスタンス初期化します。

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

Dim instance As New MenuItemCollection
public MenuItemCollection ()
public:
MenuItemCollection ()
public MenuItemCollection ()
public function MenuItemCollection ()
解説解説
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
MenuItemCollection クラス
MenuItemCollection メンバ
System.Web.UI.WebControls 名前空間
Menu クラス
MenuItem クラス
Menu.Items プロパティ
MenuItem.ChildItems プロパティ

MenuItemCollection コンストラクタ

MenuItemCollection クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

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

関連項目

MenuItemCollection クラス
MenuItemCollection メンバ
System.Web.UI.WebControls 名前空間
Menu クラス
MenuItem クラス
Menu.Items プロパティ
MenuItem.ChildItems プロパティ

MenuItemCollection コンストラクタ (MenuItem)

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

メニュー項目 (または所有者) を指定してMenuItemCollection クラス新しインスタンス初期化します。

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

Public Sub New ( _
    owner As MenuItem _
)
Dim owner As MenuItem

Dim instance As New MenuItemCollection(owner)
public MenuItemCollection (
    MenuItem owner
)
public:
MenuItemCollection (
    MenuItem^ owner
)
public MenuItemCollection (
    MenuItem owner
)
public function MenuItemCollection (
    owner : MenuItem
)

パラメータ

owner

現在の MenuItemCollection の親メニュー項目を表す MenuItem。

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

MenuItemCollection プロパティ


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

  名前 説明
パブリック プロパティ Count 現在の MenuItemCollection オブジェクト内のメニュー項目の数を取得します
パブリック プロパティ IsSynchronized MenuItemCollection オブジェクトへのアクセス同期されている (スレッド セーフである) かどうかを示す値を取得します
パブリック プロパティ Item 現在の MenuItemCollection オブジェクト内の指定したインデックス位置にある MenuItem オブジェクト取得します
パブリック プロパティ SyncRoot MenuItemCollection オブジェクトへのアクセス同期するために使用できるオブジェクト取得します
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Web.UI.IStateManager.IsTrackingViewState MenuItemCollection オブジェクトビューステートへの変更保存しているかどうかを示す値を取得します
参照参照

関連項目

MenuItemCollection クラス
System.Web.UI.WebControls 名前空間
Menu クラス
MenuItem クラス
Menu.Items プロパティ
MenuItem.ChildItems プロパティ
Count
Add
AddAt
Clear
Contains
CopyTo
CopyTo
GetEnumerator
IndexOf
Item
RemoveAt

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 から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Web.UI.IStateManager.LoadViewState MenuItemCollection オブジェクト前回保存したビューステート読み込みます。
インターフェイスの明示的な実装 System.Web.UI.IStateManager.SaveViewState ビューステートへの変更Object保存します
インターフェイスの明示的な実装 System.Web.UI.IStateManager.TrackViewState ビューステートへの変更追跡するように MenuItemCollection オブジェクト指示します
参照参照

関連項目

MenuItemCollection クラス
System.Web.UI.WebControls 名前空間
Menu クラス
MenuItem クラス
Menu.Items プロパティ
MenuItem.ChildItems プロパティ
Count
Add
AddAt
Clear
Contains
CopyTo
CopyTo
GetEnumerator
IndexOf
Item
RemoveAt

MenuItemCollection メンバ

Menu コントロール内のメニュー項目のコレクション表します。このクラス継承できません。

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


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド MenuItemCollection オーバーロードされます。 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 から継承されます。)
プロテクト メソッドプロテクト メソッド
明示的インターフェイスの実装明示的インターフェイス実装
  名前 説明
インターフェイスの明示的な実装 System.Web.UI.IStateManager.LoadViewState MenuItemCollection オブジェクト前回保存したビューステート読み込みます。
インターフェイスの明示的な実装 System.Web.UI.IStateManager.SaveViewState ビューステートへの変更Object保存します
インターフェイスの明示的な実装 System.Web.UI.IStateManager.TrackViewState ビューステートへの変更追跡するように MenuItemCollection オブジェクト指示します
インターフェイスの明示的な実装 System.Web.UI.IStateManager.IsTrackingViewState MenuItemCollection オブジェクトビューステートへの変更保存しているかどうかを示す値を取得します
参照参照

関連項目

MenuItemCollection クラス
System.Web.UI.WebControls 名前空間
Menu クラス
MenuItem クラス
Menu.Items プロパティ
MenuItem.ChildItems プロパティ
Count
Add
AddAt
Clear
Contains
CopyTo
CopyTo
GetEnumerator
IndexOf
Item
RemoveAt


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

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

辞書ショートカット

すべての辞書の索引

「MenuItemCollection」の関連用語

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

   

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



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

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

©2024 GRAS Group, Inc.RSS