DataGridControl is an interactive, virtualized, data-bound table control intended for large datasets and rich interaction:
scrolling, selection, searching/filtering, column resizing, and inline editing.
The lower-level contracts and data model live in DataGrid Specs.
Typical usage is:
IDataGridDocument (e.g. DataGridListDocument<T> or DataGridDataTableDocument),DataGridDocumentView) when you want sorting/filtering/search,DataGridControl.View,ScrollViewer to show scrollbars.You can bind DataGridControl.Document directly for the simplest scenario, but using a view is the recommended path
when you want projection (sort/filter) and when the source can change shape.
using XenoAtom.Terminal.UI;
using XenoAtom.Terminal.UI.Controls;
using XenoAtom.Terminal.UI.DataGrid;
public sealed partial class MyRow
{
[Bindable] public partial int Id { get; set; }
[Bindable] public partial string Name { get; set; } = string.Empty;
}
var doc = new DataGridListDocument<MyRow>()
.AddColumn(MyRow.Accessor.Id)
.AddColumn(MyRow.Accessor.Name);
using var view = new DataGridDocumentView(doc);
var grid = new DataGridControl { View = view, FrozenColumns = 1 };
// Optional: provide typed UI columns to enable typed templates/editors and per-column overrides.
grid.Columns.Add(new DataGridColumn<int>
{
Key = MyRow.Accessor.Id.Name,
TypedValueAccessor = MyRow.Accessor.Id,
Width = GridLength.Auto,
CellAlignment = TextAlignment.Right,
});
grid.Columns.Add(new DataGridColumn<string>
{
Key = MyRow.Accessor.Name.Name,
TypedValueAccessor = MyRow.Accessor.Name,
Width = GridLength.Star(1),
});
var root = new ScrollViewer(grid);
DataGridControl renders columns from the current snapshot:
IDataGridDocumentSnapshot) that describes columns + rows.IDataGridView) projects a document (filtering/sorting), and exposes CurrentSnapshot.grid.Columns.Count == 0), orgrid.Columns) if you want per-column customization.Schema-only mode supports selection, scrolling, search, filtering, and column resizing.
Add grid.Columns when you need typed templates/editors, custom header visuals, or per-column constraints.
Sizing rules are intentionally simple:
Auto: uses header width and a content sample (virtualized).Fixed: uses the given width.Star: participates in filling remaining space.You can resize columns at runtime:
Auto-size scans the entire column. For very large datasets, prefer AutoSizeSampleRowCount-style sizing
(the default auto sizing) and use auto-size on demand.
Ctrl+F: open find UI (uses SearchReplacePopup in find mode)F3 / Shift+F3: next / previous matchF4: toggle filter row (when View is filterable)F2 or Enter: edit current cell (when editable)DataGridControl supports:
Ctrl+A to select the entire table,Ctrl+C to copy the current selection.The copied format is plain text designed to paste into editors/spreadsheets (tab-separated values).
Editing is enabled when:
ReadOnly == false, andWhen editing starts, the control chooses an editor:
TextBox for strings (supports selection, scrolling inside the cell, copy/paste, undo/redo),NumberBox for numeric types,If you need a custom cell editor or display, provide a typed DataGridColumn<T> and use templates.
See Data Templating.
DataGridControl exposes a ScrollModel (via IScrollable) so ScrollViewer can render scrollbars and synchronize offsets.DataGridColumn.Key should match DataGridColumnInfo.Key from the snapshot.HorizontalAlignment = Align.Stretch, VerticalAlignment = Align.Stretch