ComboBox

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

Try on XnaFiddle.NETarrow-up-right

ComboBox displaying a list of items

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:

Try on XnaFiddle.NETarrow-up-right

ComboBox ListBox with custom Height

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.

Try on XnaFiddle.NETarrow-up-right

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.

Try on XnaFiddle.NETarrow-up-right

Last updated

Was this helpful?