New to Telerik UI for WinForms? Download free 30-day trial

Adding and Removing Tabs and RibbonBar Groups

You can manipulate RadRibbonBar tabs and groups at run time by using the appropriate collections.

Adding a Tab

To add a tab to RadRibbonBar, follow the four steps below:

  1. Create a new Telerik.WinControls.UI.RibbonTab object and set its properties.

  2. Call the Add method of the RadRibbonBar.CommandTabs collection, passing the Telerik.WinControls.UI.RibbonTab object.

Adding a tab to RadRibbonBar

RibbonTab tabItem1 = new RibbonTab();
tabItem1.Text = "Manage";
radRibbonBar1.CommandTabs.Add(tabItem1);

Dim TabItem1 As RibbonTab = New RibbonTab()
TabItem1.Text = "Manage"
RadRibbonBar1.CommandTabs.Add(TabItem1)

To add multiple tabs in a single operation, call AddRange method of RadRibbonBar.CommandTabs collection.

Adding multiple tabs to RadRibbonBar

RibbonTab tabItem2 = new RibbonTab();
RibbonTab tabItem3 = new RibbonTab();
RibbonTab tabItem4 = new RibbonTab();
tabItem1.Text = "Write";
tabItem2.Text = "Layout";
tabItem3.Text = "Image";
radRibbonBar1.CommandTabs.AddRange(new RibbonTab[] { tabItem2, tabItem3, tabItem4 });

Dim tabItem2 As New RibbonTab()
Dim tabItem3 As New RibbonTab()
Dim tabItem4 As New RibbonTab()
tabItem1.Text = "Write"
tabItem2.Text = "Layout"
tabItem3.Text = "Image"
RadRibbonBar1.CommandTabs.AddRange(New RibbonTab() {tabItem2, tabItem3, tabItem4})

Removing a Tab

To remove a tab, call the Remove method of the CommandTabs collection, specifying the RibbonTab that you wish to remove:

Remove a Tab from RadRibbonBar

RibbonTab ribbonTab2 = (RibbonTab)radRibbonBar1.CommandTabs[1];
radRibbonBar1.CommandTabs.Remove(ribbonTab2);

Dim ribbonTab2 As RibbonTab = RadRibbonBar1.CommandTabs(1)
RadRibbonBar1.CommandTabs.Remove(ribbonTab2)

To remove a tab by index, you can use RemoveAt method:

Remove a Tab by Index

radRibbonBar1.CommandTabs.RemoveAt(1);

RadRibbonBar1.CommandTabs.RemoveAt(1)

Adding a RibbonBar Group

To add a RibbonBar group to a tab, you follow the steps below:

  1. Create a new RadRibbonBarGroup object and set its properties.

  2. Call the Add method of the RadRibbonBar.CommandTab.Items collection, passing the RadRibbonBarGroup object.

Create and Setup New RadRibbonBarGroup

RadRibbonBarGroup radRibbonBarGroup1 = new RadRibbonBarGroup();
radRibbonBarGroup1.Text = "Options";
((RibbonTab)radRibbonBar1.CommandTabs[0]).Items.Add(radRibbonBarGroup1);

Dim RadRibbonBarGroup1 As RadRibbonBarGroup = New RadRibbonBarGroup()
RadRibbonBarGroup1.Text = "Options"
DirectCast(Me.RadRibbonBar1.CommandTabs(0), RibbonTab).Items.Add(RadRibbonBarGroup1)

To add multiple RibbonBar groups in a single operation, call the AddRange method of RadRibbonBar.CommandTab.Items collection:

Add Multiple RadRibbonBarGroups

RadRibbonBarGroup radRibbonBarGroup2 = new RadRibbonBarGroup();
RadRibbonBarGroup radRibbonBarGroup3 = new RadRibbonBarGroup();
RadRibbonBarGroup radRibbonBarGroup4 = new RadRibbonBarGroup();
radRibbonBarGroup2.Text = "Options";
radRibbonBarGroup3.Text = "Text";
radRibbonBarGroup4.Text = "Alignment";
RibbonTab ribbonTab1 = (RibbonTab)radRibbonBar1.CommandTabs[0];
ribbonTab1.Items.AddRange(new Telerik.WinControls.RadItem[] { radRibbonBarGroup2, radRibbonBarGroup3, radRibbonBarGroup4});

Dim RadRibbonBarGroup2 As RadRibbonBarGroup = New RadRibbonBarGroup()
Dim RadRibbonBarGroup3 As RadRibbonBarGroup = New RadRibbonBarGroup()
Dim RadRibbonBarGroup4 As RadRibbonBarGroup = New RadRibbonBarGroup()
RadRibbonBarGroup2.Text = "Options"
RadRibbonBarGroup3.Text = "Text"
RadRibbonBarGroup4.Text = "Alignment"
Dim RibbonTab1 As RibbonTab = RadRibbonBar1.CommandTabs(0)
RibbonTab1.Items.AddRange(New Telerik.WinControls.RadItem() {RadRibbonBarGroup2, RadRibbonBarGroup3, RadRibbonBarGroup4})

Removing a RibbonBar Group

To remove a group, call the Remove method of the CommandTab.Items collection, specifying the RadRibbonBarGroup that you wish to be removed:

Remove RadRibbonBarGroup

RadRibbonBarGroup groupToRemove = ((RadRibbonBarGroup)(((RibbonTab) radRibbonBar1.CommandTabs[0]).Items[0]));
((RibbonTab)radRibbonBar1.CommandTabs[0]).Items.Remove(groupToRemove);

Dim groupToRemove As RadRibbonBarGroup = DirectCast(RadRibbonBar1.CommandTabs(0), RibbonTab).Items(0)
DirectCast(RadRibbonBar1.CommandTabs(0), RibbonTab).Items.Remove(groupToRemove)

To remove a group by index, you can use the RemoveAt method:

Remove RadRibbonBarGroup by Index

((RibbonTab)radRibbonBar1.CommandTabs[0]).Items.RemoveAt(1);

DirectCast(RadRibbonBar1.CommandTabs(0), RibbonTab).Items.RemoveAt(1)

See Also

In this article