Adding and Removing Groups and Buttons
You can manipulate groups and buttons of RadRibbonBar at run time by using the appropriate objects and collections.
Adding a Button
To add a button to a RibbonBar group of RadRibbonBar, create a new RadButtonElement and add it to RadRibbonBarGroup.Items collection:
Add a button to RadRibbonBarGroup
RadButtonElement radButtonElement1 = new RadButtonElement();
radButtonElement1.Text = "Button";
radRibbonBarGroup1.Items.Add(radButtonElement1);
Like the other collections, you can add multiple buttons in a single operation by using the appropriate AddRange method:
Add multiple buttons to RadRibbonBarGroup
RadButtonElement radButtonElement2 = new RadButtonElement();
RadButtonElement radButtonElement3 = new RadButtonElement();
radButtonElement2.Text = "Second Button";
radButtonElement3.Text = "Third Button";
radRibbonBarGroup1.Items.AddRange(new RadItem[] { radButtonElement1, radButtonElement2 });
Removing a Button
To remove a button, call the Remove method of RadRibbonBarGroup.Items collection, specifying the RadButtonElement that you wish to be removed:
Remove a button from RadRibbonBarGroup
RadButtonElement elementToRemove = (RadItem)radRibbonBarGroup1.Items[1] as RadButtonElement;
radRibbonBarGroup1.Items.Remove(elementToRemove);
To remove a button by index, you can use the RemoveAt method:
Remove a button from RadRibbonBarGroup by index
radRibbonBarGroup1.Items.RemoveAt(1);
Adding a Button Group with Buttons
To add a new button group with buttons to a RibbonBar group of RadRibbonBar, follow these steps:
-
Create a new RadRibbonBarButtonGroup object and set its properties.
-
Create a RadButtonElement objects and set their properties.
-
Add the RadButtonElement objects to the RadButtonBarGroup.Items collection.
-
Add the RadButtonBarGroup object to the RadRibbonBarGroup.Items collection.
Add button group with buttons
RadRibbonBarButtonGroup radRibbonBarButtonGroup1 = new RadRibbonBarButtonGroup();
radRibbonBarButtonGroup1.Orientation = System.Windows.Forms.Orientation.Horizontal;
radRibbonBarButtonGroup1.MinSize = new System.Drawing.Size(22, 22);
radRibbonBarButtonGroup1.ShowBorder = true;
RadButtonElement radButtonElement4 = new RadButtonElement();
RadButtonElement radButtonElement5 = new RadButtonElement();
radButtonElement4.Text = "Button One";
radButtonElement5.Text = "Button Two";
radRibbonBarButtonGroup1.Items.AddRange(new RadItem[] { radButtonElement1, radButtonElement2 });
radRibbonBarGroup1.Items.Add(radRibbonBarButtonGroup1);