Table
The Table widget displays data in a tabular format with columns, rows, headers, and selection support.
Overview
Section titled “Overview”Table is ideal for displaying structured data like lists of items, records, or any tabular information. It supports keyboard navigation, row selection, and various column types.
Properties
Section titled “Properties”Columns (IReadOnlyList<TableColumn>)
Section titled “Columns (IReadOnlyList<TableColumn>)”The table columns.
foreach (var column in table.Columns){ Console.WriteLine(column.Name);}Rows (IReadOnlyList<TableRow>)
Section titled “Rows (IReadOnlyList<TableRow>)”The table rows.
foreach (var row in table.Rows){ // Access row data}DataSource (IEnumerable?)
Section titled “DataSource (IEnumerable?)”An enumerable data source. Setting this automatically rebuilds rows.
table.DataSource = myDataList;SelectedRowIndex (int)
Section titled “SelectedRowIndex (int)”The index of the selected row (-1 if none).
table.SelectedRowIndex = 0;SelectedRow (TableRow?, read-only)
Section titled “SelectedRow (TableRow?, read-only)”The currently selected row.
var selected = table.SelectedRow;ShowHeader (bool)
Section titled “ShowHeader (bool)”Whether to show the header row (default: true).
table.ShowHeader = true;ShowGridLines (bool)
Section titled “ShowGridLines (bool)”Whether to show grid lines between columns (default: true).
table.ShowGridLines = true;Color Properties
Section titled “Color Properties”HeaderForegroundColor: Text color for headerHeaderBackgroundColor: Background color for headerSelectedRowBackgroundColor: Background for selected rowSelectedRowForegroundColor: Text color for selected rowGridLineColor: Color of grid linesEmptyStateForegroundColor: Color for empty state message
Empty State
Section titled “Empty State”EmptyStateMessage: Message shown when table is emptyEmptyStateWidget: Custom widget shown when empty
Methods
Section titled “Methods”AddColumn(TableColumn column)
Section titled “AddColumn(TableColumn column)”Adds a column to the table.
var column = new TableColumn("Name", 20);table.AddColumn(column);AddColumn(string name, int width = 15)
Section titled “AddColumn(string name, int width = 15)”Creates and adds a column.
table.AddColumn("Name", 20);AddRow(object? data = null)
Section titled “AddRow(object? data = null)”Adds a row to the table.
var row = table.AddRow(myDataObject);RemoveRow(TableRow row)
Section titled “RemoveRow(TableRow row)”Removes a row from the table.
table.RemoveRow(row);ClearRows()
Section titled “ClearRows()”Clears all rows.
table.ClearRows();Refresh()
Section titled “Refresh()”Refreshes the table, rebuilding rows if DataSource is set.
table.Refresh();Events
Section titled “Events”RowSelected
Section titled “RowSelected”Raised when a row is selected.
table.RowSelected += (row) =>{ Console.WriteLine($"Selected: {row.Data}");};RowActivated
Section titled “RowActivated”Raised when Enter is pressed on a row.
table.RowActivated += (row) =>{ // Handle row activation};Keyboard Navigation
Section titled “Keyboard Navigation”- Up/Down Arrow: Navigate rows
- Home: Move to first row
- End: Move to last row
- Page Up/Down: Scroll by page
- Enter: Activate selected row
- Tab: Navigate to next focusable widget
Usage Example
Section titled “Usage Example”var table = new Table{ X = 1, Y = 1, Width = 70, Height = 20, ShowHeader = true, ShowGridLines = true};
table.AddColumn("Name", 30).BindTo<Person>(p => p.Name);table.AddColumn("Age", 10).BindTo<Person>(p => p.Age);table.AddColumn("City", 20).BindTo<Person>(p => p.City);
var people = new List<Person>{ new("Alice", 30, "New York"), new("Bob", 25, "London")};
table.DataSource = people;Related Widgets
Section titled “Related Widgets”- TableColumn - Column configuration
- TableRow - Row data
- Specialized Columns - CheckboxColumn, ProgressColumn