This documentation is archived and is not being maintained.

MenuItem.Index Property

Gets or sets a value indicating the position of the menu item in its parent menu.

[Visual Basic]
Public Property Index As Integer
[C#]
public int Index {get; set;}
[C++]
public: __property int get_Index();
public: __property void set_Index(int);
[JScript]
public function get Index() : int;
public function set Index(int);

Property Value

The zero-based index representing the position of the menu item in its parent menu.

Remarks

This property provides the indexed position of a menu item in the menu item collection of its parent menu. You can use this property to reposition a menu item to a different location within its menu. You can also use this property when creating a MenuItem to specify its position in a menu structure at the time of creation.

Example

[Visual Basic, C#, C++] The following example switches the position of two menu items in a menu. The following example assumes that two MenuItem objects are created named menuItem1 and menuItem2. The menuItem1 menu item moves down one position in the menu, while menuItem2 moves up one position.

[Visual Basic] 
Public Sub SwitchMyMenuItems()
    ' Move menuItem1 down one position in the menu order.
    menuItem1.Index = menuItem1.Index + 1
    ' Move menuItem2 up one position in the menu order.
    menuItem2.Index = menuItem2.Index - 1
End Sub


[C#] 
public void SwitchMyMenuItems()
{
   // Move menuItem1 down one position in the menu order.
   menuItem1.Index = menuItem1.Index + 1;
   // Move menuItem2 up one position in the menu order.
   menuItem2.Index = menuItem2.Index - 1;
}


[C++] 
public:
 void SwitchMyMenuItems()
 {
    // Move menuItem1 down one position in the menu order.
    menuItem1->Index = menuItem1->Index + 1;
    // Move menuItem2 up one position in the menu order.
    menuItem2->Index = menuItem2->Index - 1;
 }

[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: