Back to Devexpress

Toggle Button Group

windowsforms-404072-ui-templates-groups-toggle-button-group.md

latest2.1 KB
Original Source

Toggle Button Group

  • Nov 21, 2022

The Toggle Button Group (ToggleButtonGroup) is a set of two-state buttons that can be toggled on or off.

Add Toggle Buttons

Use the Items property to manage toggle buttons within the group. You can add, remove, and re-arrange buttons as needed.

csharp
using DevExpress.UITemplates.Collection.Editors;

toggleButtonGroup1.Items.AddRange(new ButtonGroupItem[] {
    new ButtonGroupItem(1, "Option A"),
    new ButtonGroupItem(2, "Option B"),
    new ButtonGroupItem(3, "Option C")
});

Toggle Button Size

Use the ItemSize property to specify the size of toggle buttons.

SizeScreenshot
Small
Default
Large

Selection

Use the Selection and SelectedValues properties to obtain selected/pressed buttons and values.

csharp
// Iterates over the selected values.
foreach(object toggleButtonValue in toggleButtonGroup1.SelectedValues) {
    // ...
}

Every time the selection changes, the button group fires the SelectedItemChanged event.

HTML & CSS Template Customization

The Toggle Button Group is created with HTML & CSS templates. This allows you to create fully custom layouts. Template customizations are handled with our HTML Template Editor that is integrated into the Visual Studio IDE. This tool uses an embedded Syntax Editor with autocomplete, tag navigation, and preview.