New to Telerik UI for WinFormsStart a free 30-day trial

Adding and Removing Groups and Buttons

Updated over 1 year ago

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

C#
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

C#
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

C#
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

C#
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:

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

  2. Create a RadButtonElement objects and set their properties.

  3. Add the RadButtonElement objects to the RadButtonBarGroup.Items collection.

  4. Add the RadButtonBarGroup object to the RadRibbonBarGroup.Items collection.

Add button group with buttons

C#
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);

See Also