Skip to main content

NavItemCollection.Add() Method

Adds a new item to the end of the collection and returns the corresponding object.

Namespace: DevExpress.XtraNavBar

Assembly: DevExpress.XtraNavBar.v23.2.dll

NuGet Packages: DevExpress.Win, DevExpress.Win.Navigation

Declaration

public virtual NavBarItem Add()

Returns

Type Description
NavBarItem

A NavBarItem object representing the newly created item.

Remarks

Use the Add method to add a new item to the NavBarControl. Modify properties of the obtained object to control the appearance and behavior of the added item.

You can access the collection of group links via the NavBarGroup.ItemLinks property. Use the NavLinkCollection.Add method of the obtained collection to create links between groups and items.

Example

The following sample code demonstrates how to add and modify groups, items and links between them. All elements are added via the Add method of the corresponding collection.

Captions are assigned to the added group and two items. This is performed via the NavElement.Caption property of the NavBarGroup and NavBarItem objects respectively. The NavElement.SmallImage property is used to display images within links.

The following image displays the control before and after code execution.

GroupsItemsLinks - Adding

using DevExpress.XtraNavBar;
// ...
// adding and adjusting a new group 
NavBarGroup helpGroup = navBarControl1.Groups.Add();
helpGroup.Caption = "Help Topics";
helpGroup.LinksUseSmallImage = true;

// adding and adjusting two items
NavBarItem indexItem = navBarControl1.Items.Add();
indexItem.Caption = "Index";
indexItem.SmallImage = Image.FromFile("E:\\Images\\Icons\\index.bmp");

NavBarItem contentsItem = navBarControl1.Items.Add();
contentsItem.Caption = "Contents";
contentsItem.SmallImage = Image.FromFile("E:\\Images\\Icons\\bookclosed.bmp");

// creating links between the group and items
helpGroup.ItemLinks.Add(indexItem);
helpGroup.ItemLinks.Add(contentsItem);
See Also