IsParent Property

MenuItem.IsParent Property

Gets a value indicating whether the menu item contains child menu items.

[Visual Basic]
Overrides Public ReadOnly Property IsParent As Boolean
[C#]
public override bool IsParent {get;}
[C++]
public: __property bool get_IsParent();
[JScript]
public override function get IsParent() : Boolean;

Property Value

true if the menu item contains child menu items; false if the menu is a standalone menu item.

Remarks

You can use this property with the Parent property to navigate in code through an entire menu structure.

Example

[Visual Basic, C#, C++] The following example determines whether there are any submenus associated with a MenuItem named menuItem1. If any submenus exist, it disables them by setting the Enabled property to false. The example assumes that there is a MenuItem object created named menuItem1.

[Visual Basic] 
Public Sub DisableMyChildMenus()
    ' Determine if menuItem2 is a parent menu.
    If menuItem2.IsParent = True Then
        ' Loop through all the submenus.
        Dim i As Integer
        For i = 0 To menuItem2.MenuItems.Count - 1
            ' Disable all of the submenus of menuItem2.
            menuItem2.MenuItems(i).Enabled = False
        Next i
    End If
End Sub


[C#] 
public void DisableMyChildMenus ()
{
   // Determine if menuItem2 is a parent menu.
   if(menuItem2.IsParent == true)
   {
      // Loop through all the submenus.
      for(int i = 0; i < menuItem2.MenuItems.Count; i++)
      {
         // Disable all of the submenus of menuItem2.
         menuItem2.MenuItems[i].Enabled = false;
      }
   }
}


[C++] 
public:
 void DisableMyChildMenus ()
 {
    // Determine if menuItem2 is a parent menu.
    if(menuItem2->IsParent == true)
    {
       // Loop through all the submenus.
       for(int i = 0; i < menuItem2->MenuItems->Count; i++)
       {
          // Disable all of the submenus of menuItem2.
          menuItem2->MenuItems->Item[i]->Enabled = false;
       }
    }
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

MenuItem Class | MenuItem Members | System.Windows.Forms Namespace

Show:
© 2016 Microsoft