Class TableControl
- Namespace
- SharpConsoleUI.Controls
- Assembly
- SharpConsoleUI.dll
A table control that renders tabular data directly to CharacterBuffer. Supports both read-only display and interactive mode with selection, keyboard navigation, scrolling, sorting, multi-selection, column resizing, inline editing, draggable scrollbars, and virtual data binding.
public class TableControl : BaseControl, IDOMPaintable, INotifyPropertyChanged, IInteractiveControl, IFocusableControl, IMouseAwareControl, IWindowControl, IDisposable
- Inheritance
-
TableControl
- Implements
- Inherited Members
- Extension Methods
Constructors
TableControl()
Initializes a new instance of the TableControl class.
public TableControl()
Properties
ActiveFilterText
Gets the active filter text, or null if no filter is active.
public string? ActiveFilterText { get; }
Property Value
AutoHighlightOnFocus
Gets or sets whether to auto-highlight the first row when the control gains focus. Default: true.
public bool AutoHighlightOnFocus { get; set; }
Property Value
BackgroundColor
public Color? BackgroundColor { get; set; }
Property Value
BorderColor
Gets or sets the border color. Null falls back to theme.
public Color? BorderColor { get; set; }
Property Value
BorderStyle
Gets or sets the border style.
public BorderStyle BorderStyle { get; set; }
Property Value
CanFocusWithMouse
Whether this control can receive focus via mouse clicks
public bool CanFocusWithMouse { get; }
Property Value
CanReceiveFocus
Whether this control can receive focus
public bool CanReceiveFocus { get; }
Property Value
CellNavigationEnabled
Gets or sets whether cell-level navigation is enabled (Tab/Left/Right to move between cells).
public bool CellNavigationEnabled { get; set; }
Property Value
CheckboxMode
Gets or sets whether checkbox mode is enabled (shows [x]/[ ] before each row). Requires MultiSelectEnabled = true.
public bool CheckboxMode { get; set; }
Property Value
ColumnCount
Gets the number of columns in the table.
public int ColumnCount { get; }
Property Value
ColumnResizeEnabled
Gets or sets whether column resizing by dragging column borders is enabled.
public bool ColumnResizeEnabled { get; set; }
Property Value
Columns
Gets the read-only list of columns.
public IReadOnlyList<TableColumn> Columns { get; }
Property Value
ContentHeight
Gets the content height.
public int? ContentHeight { get; }
Property Value
- int?
ContentWidth
Gets the minimum width needed to display the control's content, including margins. Returns null if width cannot be determined. This is calculated based on content (text length, child controls, etc.) and represents the natural/intrinsic size.
public override int? ContentWidth { get; }
Property Value
- int?
CurrentFilterMode
Gets the current filter mode.
public FilterMode CurrentFilterMode { get; }
Property Value
CurrentSortDirection
Gets the current sort direction.
public SortDirection CurrentSortDirection { get; }
Property Value
DataSource
Gets or sets the virtual data source. When set, the control ignores internal rows/columns and queries only visible rows from the source on demand. Mutually exclusive with in-memory rows.
public ITableDataSource? DataSource { get; set; }
Property Value
FilteringEnabled
Gets or sets whether filtering is enabled. Press '/' to enter filter mode.
public bool FilteringEnabled { get; set; }
Property Value
ForegroundColor
public Color? ForegroundColor { get; set; }
Property Value
FuzzyFilterEnabled
Gets or sets whether fuzzy (character-subsequence) matching is enabled as a fallback.
public bool FuzzyFilterEnabled { get; set; }
Property Value
HasFocus
public bool HasFocus { get; }
Property Value
HeaderBackgroundColor
Gets or sets the header background color. Null falls back to theme.
public Color? HeaderBackgroundColor { get; set; }
Property Value
HeaderForegroundColor
Gets or sets the header foreground color. Null falls back to theme.
public Color? HeaderForegroundColor { get; set; }
Property Value
Height
Gets or sets the explicit height.
public override int? Height { get; set; }
Property Value
- int?
HorizontalScrollOffset
Gets or sets the horizontal scroll offset (in character columns).
public int HorizontalScrollOffset { get; set; }
Property Value
HorizontalScrollbarVisibility
Gets or sets when the horizontal scrollbar should be displayed.
public ScrollbarVisibility HorizontalScrollbarVisibility { get; set; }
Property Value
InlineEditingEnabled
Gets or sets whether inline cell editing is enabled (F2 to edit, Enter to commit, Escape to cancel). Requires CellNavigationEnabled = true.
public bool InlineEditingEnabled { get; set; }
Property Value
IsEditing
Gets whether the control is currently in cell editing mode.
public bool IsEditing { get; }
Property Value
IsEnabled
Gets or sets whether this control is enabled and can receive input.
public bool IsEnabled { get; set; }
Property Value
IsFiltering
Gets whether a filter is currently active (typing or confirmed).
public bool IsFiltering { get; }
Property Value
MultiSelectEnabled
Gets or sets whether multi-selection is enabled.
public bool MultiSelectEnabled { get; set; }
Property Value
ReadOnly
Gets or sets whether the table is read-only. When true (default), the table behaves as a static display with no selection or interaction. When false, enables selection, keyboard navigation, scrolling, and other interactive features.
public bool ReadOnly { get; set; }
Property Value
RowCount
Gets the number of rows in the table.
public int RowCount { get; }
Property Value
Rows
Gets the read-only list of rows.
public IReadOnlyList<TableRow> Rows { get; }
Property Value
ScrollOffset
Gets or sets the vertical scroll offset (first visible row index).
public int ScrollOffset { get; set; }
Property Value
SelectedColumnIndex
Gets or sets the selected column index for cell navigation. -1 means no column selected.
public int SelectedColumnIndex { get; set; }
Property Value
SelectedRow
Gets the currently selected row, or null if no selection.
public TableRow? SelectedRow { get; }
Property Value
SelectedRowIndex
Gets or sets the selected row index. -1 means no selection.
public int SelectedRowIndex { get; set; }
Property Value
ShowHeader
Gets or sets whether to show the header row.
public bool ShowHeader { get; set; }
Property Value
ShowRowSeparators
Gets or sets whether to show row separators.
public bool ShowRowSeparators { get; set; }
Property Value
SortColumnIndex
Gets the current sort column index, or -1 if no sort is applied.
public int SortColumnIndex { get; }
Property Value
SortingEnabled
Gets or sets whether sorting is enabled. When enabled, clicking a header column cycles through Ascending → Descending → None.
public bool SortingEnabled { get; set; }
Property Value
Title
Gets or sets the table title.
public string? Title { get; set; }
Property Value
TitleAlignment
Gets or sets the title alignment.
public TextJustification TitleAlignment { get; set; }
Property Value
UseSafeBorder
Gets or sets whether to use safe border characters.
public bool UseSafeBorder { get; set; }
Property Value
VerticalScrollbarVisibility
Gets or sets when the vertical scrollbar should be displayed.
public ScrollbarVisibility VerticalScrollbarVisibility { get; set; }
Property Value
WantsMouseEvents
Whether this control wants to receive mouse events
public bool WantsMouseEvents { get; set; }
Property Value
Methods
AddColumn(TableColumn)
Adds a column to the table.
public void AddColumn(TableColumn column)
Parameters
columnTableColumn
AddColumn(string, TextJustification, int?)
Adds a column with the specified header.
public void AddColumn(string header, TextJustification alignment = TextJustification.Left, int? width = null)
Parameters
headerstringalignmentTextJustificationwidthint?
AddRow(TableRow)
Adds a row to the table.
public void AddRow(TableRow row)
Parameters
rowTableRow
AddRow(params string[])
Adds a row with the specified cells.
public void AddRow(params string[] cells)
Parameters
cellsstring[]
AddRows(IEnumerable<TableRow>)
Adds multiple rows to the table.
public void AddRows(IEnumerable<TableRow> rows)
Parameters
rowsIEnumerable<TableRow>
ApplyFilter(CompoundFilterExpression)
Applies a compound filter expression. Sets mode to Confirmed.
public void ApplyFilter(CompoundFilterExpression compound)
Parameters
compoundCompoundFilterExpression
ApplyFilter(FilterExpression)
Applies a pre-built filter expression. Wraps it into a compound expression.
public void ApplyFilter(FilterExpression expression)
Parameters
expressionFilterExpression
ApplyFilter(string)
Applies a filter programmatically. Sets mode to Confirmed.
public void ApplyFilter(string filterText)
Parameters
filterTextstring
ClearColumns()
Clears all columns.
public void ClearColumns()
ClearFilter()
Clears any active filter, restoring all rows.
public void ClearFilter()
ClearRows()
Clears all rows.
public void ClearRows()
ClearSelection()
Clears all selection (multi-select mode).
public void ClearSelection()
ClearSort()
Clears any active sort, restoring original order.
public void ClearSort()
Create()
Creates a new TableControlBuilder for fluent configuration.
public static TableControlBuilder Create()
Returns
FilterByColumn(int, string, FilterOperator)
Filters by a specific column programmatically.
public void FilterByColumn(int columnIndex, string value, FilterOperator op = FilterOperator.Contains)
Parameters
columnIndexintvaluestringopFilterOperator
GetCell(int, int)
Gets a cell value.
public string GetCell(int row, int column)
Parameters
Returns
GetCheckedRows()
Gets all checked rows (checkbox mode).
public List<TableRow> GetCheckedRows()
Returns
GetLogicalContentSize()
Gets the logical size of the control's content without rendering.
public override Size GetLogicalContentSize()
Returns
- Size
The size representing the content's natural dimensions.
GetRow(int)
Gets a row.
public TableRow GetRow(int index)
Parameters
indexint
Returns
GetSelectedRows()
Gets all selected rows in multi-select mode.
public List<TableRow> GetSelectedRows()
Returns
GetVisibleRowCount()
Gets the number of visible rows based on the current rendering area.
public int GetVisibleRowCount()
Returns
MeasureDOM(LayoutConstraints)
Measures the control's desired size given the available constraints.
public override LayoutSize MeasureDOM(LayoutConstraints constraints)
Parameters
constraintsLayoutConstraintsThe layout constraints (min/max width/height).
Returns
- LayoutSize
The desired size of the control.
OnDisposing()
Called during Dispose() before Container is set to null.
Override to perform control-specific cleanup (null events, close portals, clear data, etc.).
protected override void OnDisposing()
PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)
Paints the control's content directly to a CharacterBuffer.
public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultFg, Color defaultBg)
Parameters
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultFgColordefaultBgColor
ProcessKey(ConsoleKeyInfo)
Processes a keyboard input event.
public bool ProcessKey(ConsoleKeyInfo key)
Parameters
keyConsoleKeyInfoThe key information for the pressed key.
Returns
- bool
True if the key was handled by this control; otherwise, false.
ProcessMouseEvent(MouseEventArgs)
Processes a mouse event for this control
public bool ProcessMouseEvent(MouseEventArgs args)
Parameters
argsMouseEventArgsMouse 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
indexint
RemoveRow(int)
Removes the row at the specified index.
public void RemoveRow(int index)
Parameters
indexint
SelectAll()
Selects all rows (multi-select mode).
public void SelectAll()
SetColumnAlignment(int, TextJustification)
Sets the alignment of a column.
public void SetColumnAlignment(int index, TextJustification alignment)
Parameters
indexintalignmentTextJustification
SetColumnWidth(int, int?)
Sets the width of a column.
public void SetColumnWidth(int index, int? width)
Parameters
SetData(IEnumerable<TableRow>)
Sets all rows at once.
public void SetData(IEnumerable<TableRow> rows)
Parameters
rowsIEnumerable<TableRow>
SortByColumn(int)
Sorts the table by the specified column. Cycles: None → Ascending → Descending → None.
public void SortByColumn(int columnIndex)
Parameters
columnIndexint
UpdateCell(int, int, string)
Updates a cell value.
public void UpdateCell(int row, int column, string value)
Parameters
Events
CellActivated
Occurs when a cell is activated (Enter key in cell navigation mode).
public event EventHandler<(int Row, int Column)>? CellActivated
Event Type
- EventHandler<(int Line, int Column)>
CellEditCancelled
Occurs when a cell edit is cancelled (Escape key).
public event EventHandler<(int Row, int Column)>? CellEditCancelled
Event Type
- EventHandler<(int Line, int Column)>
CellEditCompleted
Occurs when a cell edit is committed (Enter key).
public event EventHandler<(int Row, int Column, string OldValue, string NewValue)>? CellEditCompleted
Event Type
FilterApplied
Occurs when a filter is applied (confirmed).
public event EventHandler<string>? FilterApplied
Event Type
FilterCleared
Occurs when the filter is cleared.
public event EventHandler? FilterCleared
Event Type
FilterTextChanged
Occurs when the filter text changes during typing.
public event EventHandler<string>? FilterTextChanged
Event Type
MouseClick
Event fired when the control is clicked
public event EventHandler<MouseEventArgs>? MouseClick
Event Type
MouseDoubleClick
Event fired when the control is double-clicked
public event EventHandler<MouseEventArgs>? MouseDoubleClick
Event Type
MouseEnter
Event fired when the mouse enters the control area
public event EventHandler<MouseEventArgs>? MouseEnter
Event Type
MouseLeave
Event fired when the mouse leaves the control area
public event EventHandler<MouseEventArgs>? MouseLeave
Event Type
MouseMove
Event fired when the mouse moves over the control
public event EventHandler<MouseEventArgs>? MouseMove
Event Type
MouseRightClick
Event fired when the control is right-clicked (Button3)
public event EventHandler<MouseEventArgs>? MouseRightClick
Event Type
RowActivated
Occurs when a row is activated (Enter key or double-click).
public event EventHandler<int>? RowActivated
Event Type
SelectedRowChanged
Occurs when the selected row index changes.
public event EventHandler<int>? SelectedRowChanged
Event Type
SelectedRowItemChanged
Occurs when the selected row item changes.
public event EventHandler<TableRow?>? SelectedRowItemChanged