PromptPlus

PromptPlus # PromptPlus ## **TableSelect<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: TableSelect — Methods →


A paginated, filterable grid with named columns where the user picks one row and confirms with Enter.

TableSelect<T> renders any collection as a bordered table. You declare the columns (header, value selector, optional formatter, width, and alignment), feed it rows of your own type, and the user navigates rows — and, on wide tables, columns — with the keyboard. It can filter as the user types, scroll horizontally when the columns overflow, validate the highlighted row before returning it, and persist the last choice.

☑️ Need to pick several rows at once? Use the TableMultiSelect control — same grid model, with a checkbox per row.


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, columns, filtering, scrolling, validation, history, view-only
Styles The TableSelectStyles regions and how to recolor them

When to use it

Use TableSelect<T> when… Consider instead…
The data is tabular and the user picks one row
The user may check several rows TableMultiSelect
Each item is a single label (no columns) Select
The data is hierarchical TreeSelect

Minimal example

using PromptPlusLibrary;

record Product(int Id, string Name, string Category, decimal Price);

var products = new[]
{
    new Product(1, "Notebook Pro",   "Electronics", 1299.99m),
    new Product(2, "Wireless Mouse", "Peripherals",   29.90m),
    new Product(3, "4K Monitor",     "Electronics",  599.00m),
};

var result = PromptPlus.Controls
    .TableSelect<Product>("Select a product")
    .AddColumn("Id",       x => x.Id, width: 4, alignment: ColumnAlignment.Right)
    .AddColumn("Name",     x => x.Name)
    .AddColumn("Category", x => x.Category)
    .AddColumn("Price",    x => x.Price, v => $"$ {v:N2}", alignment: ColumnAlignment.Right)
    .AddItems(products)
    .Run();

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

At least one column and one row must be configured before Run, otherwise a ValidationException is thrown.


A richer example

using PromptPlusLibrary;

var product = PromptPlus.Controls
    .TableSelect<Product>("Select a product", "All column features in one table")
    .AddColumn("Id",       x => x.Id,       width: 4, alignment: ColumnAlignment.Right)
    .AddColumn("Name",     x => x.Name,     isFilterable: true)
    .AddColumn("Category", x => x.Category, alignment: ColumnAlignment.Center)
    .AddColumn("Price",    x => x.Price,    v => $"$ {v:N2}", alignment: ColumnAlignment.Right)
    .AddItems(products)
    .Filter(FilterMode.Contains, FilterTableMode.Answer)   // live filtering as the user types
    .ChangeDescription(item => $"Category: {item.Category}")
    .PageSize(8)                                            // 8 rows visible at a time
    .Run();

This combines columns, filtering, a dynamic description, 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
Define columns AddColumn
Add rows AddItem, AddItems
Load from a source Interaction, InteractionAsync
Answer text & description TextSelector, TextSelectorAsync, ChangeDescription, ChangeDescriptionAsync
Filtering & paging Filter, PageSize
Layout & borders LayoutMode, HideElements, HorizontalScroll
Initial row Default, UseDefaultHistory, DefaultMatchBy
Validate on confirm PredicateSelected, PredicateSelectedAsync
Read-only display ViewOnly
History EnableHistory
Appearance & behavior Styles, Options
Run Run

Return value

TableSelect<T> returns ResultPrompt<TableSelectResult<T>>. The TableSelectResult<T> carries the confirmed row and its table coordinates.

Member Meaning
.Content The TableSelectResult<T> (default when aborted)
.Content.Value The selected row T
.Content.RowIndex Zero-based index of the selected row
.Content.ColumnIndex Zero-based index of the focused column
.IsAborted true when the user pressed Esc

TableSelectResult<T> also deconstructs into (value, row, column):

var result = PromptPlus.Controls.TableSelect<Product>("Product")
    .AddColumn("Name", x => x.Name)
    .AddItems(products)
    .Run();

if (!result.IsAborted)
{
    var (row, rowIndex, columnIndex) = result.Content;
    PromptPlus.Console.WriteLine($"{row.Name} at row {rowIndex}, column {columnIndex}");
}

See also