PromptPlus

PromptPlus # PromptPlus ## **Select<T>** [![NuGet](https://img.shields.io/badge/NuGet-PromptPlus-blue)](https://www.nuget.org/packages/PromptPlus) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![.NET](https://img.shields.io/badge/.NET-8%20%7C%209%20%7C%2010-512BD4)](https://dotnet.microsoft.com/)

← Back to HomeNext: Select — Methods →


A scrollable, filterable list where the user picks one item and confirms with Enter.

Select<T> turns any collection into an interactive menu. It works with strings, enums, records, or your own types; it can group items under headers, filter as the user types, auto-select the last match, show extra info per row, and validate the choice before returning it.

☑️ Need to pick several items at once? Use the MultiSelect control — same list model, with checkboxes.


On this page

Sub-page What you will find
Index (this page) What it is, when to use it, first examples, the method map
Methods Every fluent method — signature, parameters, defaults, and a snippet
Operations Keyboard, filtering, grouping, validation, history, view-only
Styles The SelectStyles regions and how to recolor them

When to use it

Use Select<T> when… Consider instead…
The user picks one option from a known set
The user may pick several MultiSelect
The data is tabular (multiple columns) TableSelect
The data is hierarchical TreeSelect
It is a yes/no or single-key answer KeyPress / Confirm

Minimal example

using PromptPlusLibrary;

var result = PromptPlus.Controls
    .Select<string>("Favorite color")
    .AddItems(["Red", "Green", "Blue"])
    .Run();

if (!result.IsAborted)
    PromptPlus.Console.WriteLine($"You chose {result.Content}");

Selecting from an enum

Select<T> reads enum members automatically — including [Display(Name = ..., Order = ...)] attributes for the label and ordering. No AddItems call needed:

enum Environment { Dev, Test, Staging, Prod }

var env = PromptPlus.Controls.Select<Environment>("Target environment").Run();

A richer example

using PromptPlusLibrary;

var city = PromptPlus.Controls
    .Select<string>("Which city?", "Type to filter")
    .AddGroupedItems("North America", ["Seattle", "Boston", "New York"])
    .AddGroupedItems("Asia",          ["Tokyo", "Singapore", "Shanghai"])
    .Filter(FilterMode.Contains)     // live filtering as the user types
    .PageSize(5)                     // 5 rows visible at a time
    .Run();

This combines grouping (headers), filtering, and paging — see Operations for how they behave together.


Method map

Grouped by purpose. Full signatures and examples are on the Methods page.

Purpose Methods
Add items AddItem, AddItems, AddGroupedItem, AddGroupedItems, AddSeparator
Load from a source Interaction, InteractionAsync
Item text & info TextSelector, TextSelectorAsync, ExtraInfo, ExtraInfoAsync, HideTipGroup
Filtering & paging Filter, AutoSelect, PageSize
Initial value Default, UseDefaultHistory, DefaultMatchBy
Validate on confirm PredicateSelected, PredicateSelectedAsync
Read-only display ViewOnly
Dynamic description ChangeDescription, ChangeDescriptionAsync
History EnableHistory
Appearance & behavior Styles, Options
Run Run

Return value

Select<T> returns ResultPrompt<T> — the single chosen item.

Member Meaning
.Content The selected T (default of T if aborted)
.IsAborted true when the user pressed Esc
var (color, aborted) = PromptPlus.Controls
    .Select<string>("Color").AddItems(["Red", "Green"]).Run();
if (!aborted) PromptPlus.Console.WriteLine(color);

See also