Back to Devexpress

How to: Remove Bar Items

windowsforms-404106-controls-and-libraries-ribbon-bars-and-menu-examples-ribbon-how-to-remove-bar-items.md

latest1.2 KB
Original Source

How to: Remove Bar Items

  • Sep 09, 2022

To remove a bar item, remove it from the RibbonControl.Items collection. This also removes all bar item links.

csharp
// Removes the bar item and all its links.
ribbon.Items.Remove(barButtonItem1);
vb
' Removes the bar item and all its links.
ribbon.Items.Remove(barButtonItem1)

The following example shows how to remove all bar items from a Ribbon Page Group.

csharp
using DevExpress.XtraBars.Ribbon;

void ClearRibbonGroup(RibbonPageGroup ribbonGroup, RibbonControl ribbon) {
    var count = ribbonGroup.ItemLinks.Count;
    for(int i = 0; i < count; i++)
        ribbon.Items.Remove(ribbonGroup.ItemLinks.First().Item);
}
vb
Imports DevExpress.XtraBars.Ribbon

Private Sub ClearRibbonGroup(ByVal ribbonGroup As RibbonPageGroup, ByVal ribbon As RibbonControl)
    Dim count = ribbonGroup.ItemLinks.Count
    For i As Integer = 0 To count - 1
        ribbon.Items.Remove(ribbonGroup.ItemLinks.First().Item)
    Next i
End Sub