Vixen
02b45cc4
csharp
public sealed class DataGrid

A table, of which only what is on screen exists as elements.

No guide page documents this yet — the page shows what the code says about itself.

Remarks

Virtualised in both directions, which is what doc 09 asks of this control by name and what makes it different from the tree. A hundred columns of a hundred thousand rows is ten million cells; what exists is the twenty-odd columns and thirty-odd rows that are on screen, and neither pool is rebuilt when the other scrolls.

⚠ Frozen columns are the leading n, not a flag on a column. Freezing an arbitrary subset raises a question with no good answer — what happens when a frozen column is dragged to the middle — and every grid that offers it ends up reordering the columns behind the user's back. FrozenColumns says how many stay put, and MoveColumn is what puts a column among them.

⚠ A frozen cell is positioned against the scroll offset, not against the content. The rows live inside the scroller, so everything in them moves left as the view scrolls right; a frozen cell adds the scroll offset back. That is one line and it is the entire mechanism — there is no second scroller and no second element tree.

⚠ Sorting and grouping are a view over the items, never a reorder of them. The list belongs to the caller, who is very likely iterating it elsewhere, and a grid that sorted in place would silently reorder a game's entity list because somebody clicked a column heading.

Fields and properties (19)

  • public const int Overscan

    How many rows are realised above and below the viewport.

  • protected override string TagName

    The element name this type answers to when a caller does not choose one.

  • protected override bool AcceptsFocus

    Whether the focus can rest on this kind of control at all.

  • public UiElement Header

    The strip of headings.

  • public ScrollView Scroller

    The scroller the rows live in.

  • public IReadOnlyList<DataColumn> Columns

    The columns, left to right.

  • public IReadOnlyList<object> Items

    What is being shown.

  • public IReadOnlyList<DataRow> Rows

    The rows that exist as elements, including the parked ones.

  • public IReadOnlyList<DataHeaderCell> Headers

    The header cells that exist.

  • public int RowCount

    How many lines the view has, group headers included.

  • public IReadOnlyCollection<int> Selection

    Which items are selected, by their index in Items.

  • public float RowHeight

    How tall a row is, from --row-height.

  • public int FrozenColumns
  • public bool MultiSelect
  • public DataColumn? SortColumn

    Which column the view is sorted by, or null.

  • public bool SortDescending

    Which way.

  • public DataColumn? GroupColumn

    Which column the view is grouped by, or null.

  • public static readonly UiPropertyKey FrozenColumnsProperty

    Identity for FrozenColumns.

  • public static readonly UiPropertyKey MultiSelectProperty

    Identity for MultiSelect.

Events (3)

  • public Action<DataGrid>? SelectionChanged

    Raised when the selection changes.

  • public Action<DataGrid, object, DataColumn>? CellEdited

    Raised after an inline edit is committed.

  • public Action<DataGrid, object>? Activated

    Raised when a row is double-clicked.

Methods (16)

  • protected override void OnCreated()

    Builds whatever this element is made of, once, as it joins a document.

  • public DataColumn AddColumn(string header, Func<object, object?>? value = null)

    Adds a column on the right.

  • public DataColumn AddColumn(DataColumn column)

    Adds a column that was made elsewhere.

  • public int IndexOf(DataColumn column)

    Where a column currently is, left to right.

  • public void MoveColumn(int from, int to)

    Moves a column to another position.

  • public void SetItems(IEnumerable<object> source)

    Shows a list of objects.

  • public void SortBy(DataColumn? column, bool descending = false)

    Sorts the view by a column, or turns sorting off.

  • public void GroupBy(DataColumn? column)

    Groups the view by a column, or turns grouping off.

  • public void ToggleGroup(object key)

    Collapses or expands a group.

  • public void Refresh()

    Rebuilds the view and realises the elements for it.

  • public void Select(int item, ModifierKeys modifiers = None)

    Selects a row, or adds it to or removes it from the selection.

  • public int RowIndexOf(int item)

    Which line of the view an item is on, or -1 if it is inside a collapsed group.

  • public int ItemAt(int row)

    The item a line of the view shows, or -1 for a group header.

  • public bool BeginEdit(DataCell cell)

    Puts a field in a cell so its value can be typed.

  • public void ClearFrozenColumns()

    Unsets FrozenColumns, so it takes its default or its ancestor's value again.

  • public void ClearMultiSelect()

    Unsets MultiSelect, so it takes its default or its ancestor's value again.

Used by (9)

  • DataGridTestsVixen.Ui.Controls.Advanced.Tests
  • BuildSettingsTestsVixen.Editor.App.Tests
  • BuildSettingsViewVixen.Editor.App
  • DeviceManagerViewVixen.Editor.Debugger
  • DiagnosticsPanelTestsVixen.Editor.App.Tests
  • KeyBindingsPanelTestsVixen.Editor.App.Tests
  • KeyBindingsViewVixen.Editor.Ui
  • PluginManagerViewVixen.Editor.App
  • ProfilerViewVixen.Editor.Profiler