Edit this page

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

Dim RadButtonElement1 As RadButtonElement = 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 });

Dim RadButtonElement2 As RadButtonElement = New RadButtonElement()
Dim RadButtonElement3 As RadButtonElement = 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);

Dim elementToRemove As RadButtonElement = RadRibbonBarGroup1.Items(1)
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);

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

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

Dim RadRibbonBarButtonGroup1 As RadRibbonBarButtonGroup = New RadRibbonBarButtonGroup()
RadRibbonBarButtonGroup1.Orientation = System.Windows.Forms.Orientation.Horizontal
RadRibbonBarButtonGroup1.MinSize = New System.Drawing.Size(22, 22)
RadRibbonBarButtonGroup1.ShowBorder = True
Dim RadButtonElement4 As RadButtonElement = New RadButtonElement()
Dim RadButtonElement5 As RadButtonElement = New RadButtonElement()
RadButtonElement4.Text = "Button One"
RadButtonElement5.Text = "Button Two"
RadRibbonBarButtonGroup1.Items.AddRange(New RadItem() {RadButtonElement4, RadButtonElement5})
RadRibbonBarGroup1.Items.Add(RadRibbonBarButtonGroup1)

See Also