Table of Contents

Class ListBox

Namespace
Alternet.UI
Assembly
Alternet.UI.Common.dll

Represents a control to display a list of items. Please consider using VirtualListBox instead of this control as it is faster.

[ControlCategory("Common")]
public class ListBox : VirtualListBox, IBaseObjectWithId, IDisposableObject, IBaseObject, ISupportInitialize, IFocusable, ITextProperty, IComponent, INotifyDataErrorInfo, IReadOnlyStrings, IListControlItemContainer, IListControlItemDefaults, ICheckListBox<ListControlItem>, ICustomListBox<ListControlItem>, IListControl<ListControlItem>, IListControl, ICustomListBox<object>, IListControl<object>, IControl, IDisposable, IWin32Window
Inheritance
ListBox
Implements
Derived

Examples

Here is how to declare a ListBox in UIXML:

<ListBox Margin="8" Name="listBox" SelectionChanged="ListBox_SelectionChanged"/>

And the corresponding event handler in the code-behind:

private void ListBox_SelectionChanged(object? sender, EventArgs e)
{
    App.Log("ListBox: SelectionChanged. SelectedIndex: " + listBox.SelectedIndex.ToString());
}

Also, a ListBox can be created from code:

var ListBox = new Alternet.UI.ListBox();
ListBox.Items.Add("One");
ListBox.Items.Add("Two");
ListBox.Items.Add("Three");
ListBox.SelectedIndex = 1;

Remarks

Examples of how a ListBox can look on different platforms:

A ListBox, like any other Control, can be disabled by setting its Enabled property to false.

Constructors

ListBox()

Initializes a new instance of the ListBox class.

ListBox(Control)

Initializes a new instance of the ListBox class with the specified parent control.

Properties

BaseItems

Gets or sets items as collection ListControlItem items. This is the fastest way to access items.

FirstItem

Gets first item in the control or null if there are no items.

this[int]

Gets or sets the Items element at the specified index.

this[long]

Gets or sets the Items element at the specified index.

this[int?]

Gets or sets the Items element at the specified index.

Items

Gets or sets items.

LastItem

Gets last item in the control or null if there are no items.

LastRootItem

Gets last root item in the control or null if there are no items.

SelectedItem

Gets or sets the currently selected item in the control.

SelectedItems

Gets an array of the selected items.

SelectedItemsCollection

Gets a collection of the selected items.

Methods

Add(object)

Adds an object to the end of the Items collection.

DataToItem(object?)

Finds the item with the specified data.

GetItem(int)

Gets item with the specified index.

ItemToData(ListControlItem?)

Gets data associated with the item.

SetCount(int, Func<object>)

Changes the number of elements in the Items.

SetItem(int, object)

Sets item with the specified index.

SetItemData(ListControlItem?, object?)

Sets item data.