Table of Contents

Class TableControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

A table control that wraps Spectre.Console's Table widget. Provides read-only display of tabular data with theming support.

public class TableControl : IDOMPaintable, IMouseAwareControl, IWindowControl, IDisposable
Inheritance
TableControl
Implements
Inherited Members
Extension Methods

Constructors

TableControl()

Initializes a new instance of the TableControl class.

public TableControl()

Properties

ActualHeight

public int? ActualHeight { get; }

Property Value

int?

ActualWidth

Gets the actual rendered width of the control, or null if not yet rendered.

public int? ActualWidth { get; }

Property Value

int?

BackgroundColor

public Color? BackgroundColor { get; set; }

Property Value

Color?

BorderColor

Gets or sets the border color. Null falls back to theme.

public Color? BorderColor { get; set; }

Property Value

Color?

BorderStyle

Gets or sets the border style.

public BorderStyle BorderStyle { get; set; }

Property Value

BorderStyle

CanFocusWithMouse

Whether this control can receive focus via mouse clicks

public bool CanFocusWithMouse { get; set; }

Property Value

bool

ColumnCount

Gets the number of columns in the table.

public int ColumnCount { get; }

Property Value

int

Columns

Gets the read-only list of columns.

public IReadOnlyList<TableColumn> Columns { get; }

Property Value

IReadOnlyList<TableColumn>

Container

Gets or sets the parent container that hosts this control.

public IContainer? Container { get; set; }

Property Value

IContainer

ForegroundColor

public Color? ForegroundColor { get; set; }

Property Value

Color?

HeaderBackgroundColor

Gets or sets the header background color. Null falls back to theme.

public Color? HeaderBackgroundColor { get; set; }

Property Value

Color?

HeaderForegroundColor

Gets or sets the header foreground color. Null falls back to theme.

public Color? HeaderForegroundColor { get; set; }

Property Value

Color?

Height

public int? Height { get; set; }

Property Value

int?

HorizontalAlignment

Gets or sets the horizontal alignment of the control within its container.

public HorizontalAlignment HorizontalAlignment { get; set; }

Property Value

HorizontalAlignment

Margin

Gets or sets the margin (spacing) around the control.

public Margin Margin { get; set; }

Property Value

Margin

Name

Gets or sets the unique name identifier for this control, used for lookup.

public string? Name { get; set; }

Property Value

string

RowCount

Gets the number of rows in the table.

public int RowCount { get; }

Property Value

int

Rows

Gets the read-only list of rows.

public IReadOnlyList<TableRow> Rows { get; }

Property Value

IReadOnlyList<TableRow>

ShowHeader

Gets or sets whether to show the header row.

public bool ShowHeader { get; set; }

Property Value

bool

ShowRowSeparators

Gets or sets whether to show row separators.

public bool ShowRowSeparators { get; set; }

Property Value

bool

StickyPosition

Gets or sets whether this control should stick to the top or bottom during scrolling.

public StickyPosition StickyPosition { get; set; }

Property Value

StickyPosition

Tag

Gets or sets an arbitrary object value that can be used to store custom data.

public object? Tag { get; set; }

Property Value

object

Title

Gets or sets the table title.

public string? Title { get; set; }

Property Value

string

TitleAlignment

Gets or sets the title alignment.

public Justify TitleAlignment { get; set; }

Property Value

Justify

UseSafeBorder

Gets or sets whether to use safe border characters.

public bool UseSafeBorder { get; set; }

Property Value

bool

VerticalAlignment

Gets or sets the vertical alignment of the control within its container.

public VerticalAlignment VerticalAlignment { get; set; }

Property Value

VerticalAlignment

Visible

Gets or sets whether this control is visible.

public bool Visible { get; set; }

Property Value

bool

WantsMouseEvents

Whether this control wants to receive mouse events

public bool WantsMouseEvents { get; set; }

Property Value

bool

Width

Gets or sets the explicit width of the control, or null for automatic sizing.

public int? Width { get; set; }

Property Value

int?

Methods

AddColumn(TableColumn)

Adds a column to the table.

public void AddColumn(TableColumn column)

Parameters

column TableColumn

AddColumn(string, Justify, int?)

Adds a column with the specified header.

public void AddColumn(string header, Justify alignment = Justify.Left, int? width = null)

Parameters

header string
alignment Justify
width int?

AddRow(TableRow)

Adds a row to the table.

public void AddRow(TableRow row)

Parameters

row TableRow

AddRow(params string[])

Adds a row with the specified cells.

public void AddRow(params string[] cells)

Parameters

cells string[]

AddRows(IEnumerable<TableRow>)

Adds multiple rows to the table.

public void AddRows(IEnumerable<TableRow> rows)

Parameters

rows IEnumerable<TableRow>

ClearColumns()

Clears all columns.

public void ClearColumns()

ClearRows()

Clears all rows.

public void ClearRows()

Create()

Creates a new TableControlBuilder for fluent configuration.

public static TableControlBuilder Create()

Returns

TableControlBuilder

Dispose()

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

public void Dispose()

GetCell(int, int)

Gets a cell value.

public string GetCell(int row, int column)

Parameters

row int
column int

Returns

string

GetLogicalContentSize()

Gets the logical size of the control's content without rendering.

public Size GetLogicalContentSize()

Returns

Size

The size representing the content's natural dimensions.

GetRow(int)

Gets a row.

public TableRow GetRow(int index)

Parameters

index int

Returns

TableRow

Invalidate()

Marks this control as needing to be re-rendered.

public void Invalidate()

MeasureDOM(LayoutConstraints)

Measures the control's desired size given the available constraints.

public LayoutSize MeasureDOM(LayoutConstraints constraints)

Parameters

constraints LayoutConstraints

The layout constraints (min/max width/height).

Returns

LayoutSize

The desired size of the control.

PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)

Paints the control's content directly to a CharacterBuffer.

public void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultFg, Color defaultBg)

Parameters

buffer CharacterBuffer

The buffer to paint to.

bounds LayoutRect

The absolute bounds where the control should paint.

clipRect LayoutRect

The clipping rectangle (visible area).

defaultFg Color
defaultBg Color

ProcessMouseEvent(MouseEventArgs)

Processes a mouse event for this control

public bool ProcessMouseEvent(MouseEventArgs args)

Parameters

args MouseEventArgs

Mouse event arguments with control-relative coordinates

Returns

bool

True if the event was handled and should not propagate further

RemoveColumn(int)

Removes the column at the specified index.

public void RemoveColumn(int index)

Parameters

index int

RemoveRow(int)

Removes the row at the specified index.

public void RemoveRow(int index)

Parameters

index int

SetColumnAlignment(int, Justify)

Sets the alignment of a column.

public void SetColumnAlignment(int index, Justify alignment)

Parameters

index int
alignment Justify

SetColumnWidth(int, int?)

Sets the width of a column.

public void SetColumnWidth(int index, int? width)

Parameters

index int
width int?

SetData(IEnumerable<TableRow>)

Sets all rows at once.

public void SetData(IEnumerable<TableRow> rows)

Parameters

rows IEnumerable<TableRow>

UpdateCell(int, int, string)

Updates a cell value.

public void UpdateCell(int row, int column, string value)

Parameters

row int
column int
value string

Events

MouseClick

Event fired when the control is clicked

public event EventHandler<MouseEventArgs>? MouseClick

Event Type

EventHandler<MouseEventArgs>

MouseDoubleClick

Event fired when the control is double-clicked

public event EventHandler<MouseEventArgs>? MouseDoubleClick

Event Type

EventHandler<MouseEventArgs>

MouseEnter

Event fired when the mouse enters the control area

public event EventHandler<MouseEventArgs>? MouseEnter

Event Type

EventHandler<MouseEventArgs>

MouseLeave

Event fired when the mouse leaves the control area

public event EventHandler<MouseEventArgs>? MouseLeave

Event Type

EventHandler<MouseEventArgs>

MouseMove

Event fired when the mouse moves over the control

public event EventHandler<MouseEventArgs>? MouseMove

Event Type

EventHandler<MouseEventArgs>