Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

ComboBox (Dropdown)

Introduction

The ComboBox control provides a compact way for users to select from a list of options.

Code Example: Adding a ComboBox

// Initialize
var comboBox = new ComboBox();
comboBox.AddToRoot();
for(int i = 0; i < 10; i++)
{
    comboBox.Items.Add($"Item {i}");
}
ComboBox displaying a list of items

ComboBox's internal ListBox is hidden until the dropdown opens, so Gum automatically skips layout when adding items. This means adding hundreds of items to a ComboBox is fast without any extra code. If you are adding many items to a visible ListBox or other ItemsControl, see Reducing Layout Calls for how to suspend layout during bulk adds.

Closing the Drop-Down

Pressing Escape closes an open drop-down and keeps the current selection. This works however the drop-down was opened. Escape pressed while the drop-down is closed is left for other controls to use.

Available in November 2026, or now if building Gum from source.

DropDownOpened is raised once each time the drop-down opens. DropDownClosed is raised once each time an open drop-down closes. Both are raised however the change happened, so a handler does not need to cover each route separately:

  • DropDownOpened: mouse, keyboard, gamepad, or setting IsDropDownOpen to true

  • DropDownClosed: picking an item, Escape, clicking away, losing focus, the ComboBox being disabled, hidden, or removed, or setting IsDropDownOpen to false

Available in November 2026, or now if building Gum from source.

Adjusting the Drop-Down ListBox

ComboBox provides a ListBox property which can be used to customize the ListBox instance.

This can be modified, even if it hasn't yet been shown. The following code shows how to modify the default size of the ListBox:

ComboBox ListBox with custom Height

The ListBox property returns a fully functional ListBox instance. For more information on how to customize the ListBox, see the ListBox page.

Performance with Many Items

If all items in the ComboBox dropdown are the same height (no text wrapping or variable-sized icons), you can improve dropdown open performance by setting UseFixedStackChildrenSize on the ListBox's inner panel. This tells the layout engine to measure only the first child and assume all others are the same size, skipping per-child measurement.

SelectedObject and SelectedIndex

Use SelectedIndex to select an item by its zero-based position in Items, or read it back to find which item is currently selected. Use SelectedObject to get or set the selected item directly as an object.

SelectionChanged

The SelectionChanged event fires whenever the user picks a different item. The handler receives a SelectionChangedEventArgs with information about the previously and newly selected items. You can also read SelectedObject or SelectedIndex directly inside the handler.

Last updated

Was this helpful?