Table of Contents

Class DropDownList

Namespace
Terminal.Gui.Views
Assembly
Terminal.Gui.dll

A dropdown/combo-box control that combines a TextField with a popover ListView for selecting from a list of items.

public class DropDownList : TextField, IDisposable, ISupportInitializeNotification, ISupportInitialize, IDesignable, IValue<string>, IValue
Inheritance
DropDownList
Implements
Inherited Members
Extension Methods

Remarks

DropDownList provides a modern dropdown control that can operate in two modes:

  • ReadOnly mode (ReadOnly = true): Acts like a traditional dropdown where clicking anywhere opens the list. The text field is not editable.
  • Editable mode (ReadOnly = false): Acts like a combo box where the user can type text or select from the list.

Key Features:

  • Toggle dropdown with button click, F4, or Alt+Down
  • Pre-selects matching item in list when opening
  • Returns focus to text field when closed
  • Supports IValue<TValue> interface for data binding
  • Auto-registers popover on first use

Usage Example:

var dropdown = new DropDownList
{
    Source = new ListWrapper<string> (["Option 1", "Option 2", "Option 3"]),
    ReadOnly = true,
    Text = "Option 1"
};
dropdown.ValueChanged += (s, e) => MessageBox.Query ("Selected", dropdown.Text, "Ok");

Constructors

DropDownList()

Initializes a new instance of the DropDownList class.

Properties

Source

Gets or sets the data source for the dropdown list.

Methods

Dispose(bool)

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

EnableForDesign()
EndInit()

Signals the View that initialization is ending. See ISupportInitialize.

OnAccepted(ICommandContext?)

Called when the View has been accepted. This is called after Accepting has been raised and not cancelled.

OnActivated(ICommandContext?)

Called when the View has been activated. This is called after Accepting has been raised and not cancelled.

OnGettingAttributeForRole(in VisualRole, ref Attribute)

Overrides attribute retrieval to ensure that in ReadOnly mode, the control uses the Normal or Focus attributes

OnHasFocusChanging(bool, bool, View?, View?)

Invoked when HasFocus is about to change. This method is called before the HasFocusChanging event is raised.