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:
-
Create a new Telerik.WinControls.UI.RibbonTab object and set its properties.
-
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);
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 });
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);
To remove a tab by index, you can use RemoveAt method:
Remove a Tab by Index
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);
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});
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);
To remove a group by index, you can use the RemoveAt method:
Remove RadRibbonBarGroup by Index
((RibbonTab)radRibbonBar1.CommandTabs[0]).Items.RemoveAt(1);