Table of Contents

Class ComboBox

Namespace
Alternet.UI
Assembly
Alternet.UI.dll

Represents a combo box control.

[ControlCategory("Common")]
public class ComboBox : ListControl, IBaseObject, IDisposableObject, IInputElement, ISupportInitialize, IFocusable, IWin32Window, ITextProperty, IComponent, IDisposable, IReadOnlyStrings
Inheritance
ComboBox
Implements
Extension Methods

Examples

Here is how to declare a ComboBox in UIXML:

<ComboBox Name="comboBox" Margin="8" IsEditable="false" VerticalAlignment="Top" HorizontalAlignment="Left"
          SelectedItemChanged="ComboBox_SelectedItemChanged" TextChanged="ComboBox_TextChanged" />

And the corresponding event handler in the code-behind:

private void ComboBox_TextChanged(object? sender, EventArgs e)
{
    var text = comboBox.Text == "" ? "\"\"" : comboBox.Text;
    Application.Log(text);
}

private void ComboBox_SelectedItemChanged(object? sender, EventArgs e)
{
    Application.Log($"Selected Item Text: {comboBox.SelectedItem}" + "\n" +
                    $"Index: {comboBox.SelectedIndex}");
}

Also, a ComboBox can be created from code:

var comboBox = new Alternet.UI.ComboBox();
comboBox.Items.Add("One");
comboBox.Items.Add("Two");
comboBox.Items.Add("Three");
comboBox.SelectedIndex = 1;
comboBox.SelectedItemChanged += ComboBox_SelectedItemChanged;

Remarks

A ComboBox displays a text box combined with a ListBox, which enables the user to select items from the list or enter a new value. The IsEditable property specifies whether the text portion can be edited.

To add or remove objects in the list at run time, use methods of the object returned by the Items property of the ComboBox. The list then displays the default string value for each object. You can add individual objects with the Add method of the ComboBox.Items object. You can delete items with the Remove method or clear the entire list with the Clear method.

In addition to display and selection functionality, the ComboBox also provides features that enable you to add items to the ComboBox and to find text within the items of the list. With the BeginUpdate() and EndUpdate() methods, you can add a large number of items to the ComboBox without the control being repainted each time an item is added to the list.

You can use the Text property to specify the string displayed in the editing field, the SelectedIndex property to get or set the current item, and the SelectedItem property to get or set a reference to the selected object.

Examples of how a ComboBox can look on different platforms:

Set Text property to specify the text displayed on the control. A ComboBox, like any other Control, can be disabled by setting its Enabled property to false.

Constructors

ComboBox()

Initializes a new instance of the ComboBox class.

Fields

SelectedItemProperty

Identifies the SelectedItem dependency property.

Properties

ControlKind

Returns control identifier.

IsEditable

Gets or a value that enables or disables editing of the text in text box area of the ComboBox.

SelectedIndex

Gets or sets the index specifying the currently selected item.

SelectedItem

Gets or sets currently selected item in the combo box.

Text

Gets or sets the text displayed in the ComboBox.

TextSelectionLength

Gets the number of characters selected in the editable portion of the combo box.

TextSelectionStart

Gets the starting index of text selected in the combo box.

UseChoiceControl

Gets or sets whether to use choice controls as readonly comboboxes.

Methods

BindEnumProp(object, string)

Binds property specified with instance and propName to the ComboBox. After binding ComboBox will edit the specified property.

BindSelectedItem(string)

Binds SelectedItem to the specified property of the DataContext

OnSelectedItemChanged(EventArgs)

Called when the value of the SelectedItem property changes.

RaiseSelectedItemChanged(EventArgs)

Raises the SelectedItemChanged event and calls OnSelectedItemChanged(EventArgs).

SelectAllText()

Selects all the text in the editable portion of the ComboBox.

SelectTextRange(int, int)

Selects a range of text in the editable portion of the ComboBox.

Events

IsEditableChanged

Occurs when the IsEditable property value changes.

SelectedItemChanged

Occurs when the SelectedItem property value changes.