Table of Contents

Class DataGrid

Namespace
Myra.Graphics2D.UI.Data
Assembly
Myra.dll

A tabular widget that displays data in rows and columns with support for column resizing, vertical scrolling, row selection, and customizable styling.

public class DataGrid : Widget, IItemWithId, INotifyAttachedPropertyChanged
Inheritance
DataGrid
Implements
Inherited Members

Constructors

DataGrid(Stylesheet, string)

Initializes a new instance of the DataGrid class with the specified stylesheet and style name.

public DataGrid(Stylesheet stylesheet, string styleName = "")

Parameters

stylesheet Stylesheet

The stylesheet to use for applying styles.

styleName string

The name of the style to apply from the stylesheet.

DataGrid(string)

Initializes a new instance of the DataGrid class using the current stylesheet.

public DataGrid(string styleName = "")

Parameters

styleName string

The name of the style to apply from the current stylesheet.

Properties

AcceptsMouseWheel

Gets a value indicating whether this widget accepts mouse wheel input.

protected override bool AcceptsMouseWheel { get; }

Property Value

bool

CanSelectNothing

Gets or sets a value indicating whether clicking an already-selected row deselects it.

public bool CanSelectNothing { get; set; }

Property Value

bool

CellHorizontalAlignment

Gets or sets the default horizontal alignment of cell content. Defaults to Left. Individual columns can override this via CellHorizontalAlignment.

public HorizontalAlignment CellHorizontalAlignment { get; set; }

Property Value

HorizontalAlignment

ClipToBounds

Gets or sets a value indicating whether the widget's content is clipped to its bounds.

public override bool ClipToBounds { get; set; }

Property Value

bool

ColumnResizeHandleWidth

Gets or sets the width in pixels of the hit-test area around a column boundary for initiating a resize drag.

public int ColumnResizeHandleWidth { get; set; }

Property Value

int

ColumnSpacing

Gets or sets the spacing in pixels between grid columns.

public int ColumnSpacing { get; set; }

Property Value

int

Columns

Gets or sets the array of column definitions that define the grid's structure and data binding. Setting this property triggers a full rebuild of columns and the grid layout.

public DataGridColumnBase[] Columns { get; set; }

Property Value

DataGridColumnBase[]

Data

Gets or sets the collection of data objects displayed as rows. Property values are resolved by name via reflection when the collection is assigned.

public IList Data { get; set; }

Property Value

IList

Desktop

Gets or sets the desktop that this widget is attached to.

public override Desktop Desktop { get; }

Property Value

Desktop

FillColumnIndex

Gets or sets the zero-based index of the column that fills the remaining horizontal space, or null to append a fill column after all data columns.

public int? FillColumnIndex { get; set; }

Property Value

int?

FilterStringComparison

Gets or sets the string comparison mode used when matching filter text against cell values. Defaults to CurrentCultureIgnoreCase.

public StringComparison FilterStringComparison { get; set; }

Property Value

StringComparison

GridLinesColor

Gets or sets the color of the grid lines.

public Color GridLinesColor { get; set; }

Property Value

Color

GridSelectionMode

Gets or sets the selection mode for the grid (None, Row, Column, or Cell).

public GridSelectionMode GridSelectionMode { get; set; }

Property Value

GridSelectionMode

HasFilter

Gets or sets a value indicating whether filter rows are displayed below the header, allowing per-column text filtering.

public bool HasFilter { get; set; }

Property Value

bool

HasHeader

Gets or sets a value indicating whether the header row is displayed.

public bool HasHeader { get; set; }

Property Value

bool

HeaderHorizontalAlignment

Gets or sets the default horizontal alignment of header text. Defaults to Left. Individual columns can override this via HeaderHorizontalAlignment.

public HorizontalAlignment HeaderHorizontalAlignment { get; set; }

Property Value

HorizontalAlignment

HorizontalAlignment

Gets or sets the horizontal alignment of the widget within its parent container.

public override HorizontalAlignment HorizontalAlignment { get; set; }

Property Value

HorizontalAlignment

HoverIndexCanBeNull

Gets or sets a value indicating whether the hover index can be cleared when the pointer leaves the grid.

public bool HoverIndexCanBeNull { get; set; }

Property Value

bool

IndexColumnCellHorizontalAlignment

Gets or sets the horizontal alignment of the index column cell numbers. When null, the DataGrid's CellHorizontalAlignment is used instead.

public HorizontalAlignment? IndexColumnCellHorizontalAlignment { get; set; }

Property Value

HorizontalAlignment?

IndexColumnHeaderHorizontalAlignment

Gets or sets the horizontal alignment of the index column header text. When null, the DataGrid's HeaderHorizontalAlignment is used instead.

public HorizontalAlignment? IndexColumnHeaderHorizontalAlignment { get; set; }

Property Value

HorizontalAlignment?

IndexColumnWidth

Gets or sets the width of the row-number index column. Defaults to 50. Set to null to hide the index column.

public int? IndexColumnWidth { get; set; }

Property Value

int?

MinColumnWidth

Gets or sets the minimum width in pixels a column can be resized to.

public int MinColumnWidth { get; set; }

Property Value

int

ResizableColumns

Gets or sets a value indicating whether columns can be resized by dragging the boundary between header cells.

public bool ResizableColumns { get; set; }

Property Value

bool

RowSpacing

Gets or sets the spacing in pixels between grid rows.

public int RowSpacing { get; set; }

Property Value

int

RowsPerPage

Gets the number of data rows visible per page, based on the current layout size.

public int RowsPerPage { get; }

Property Value

int

ScrollMultiplier

Gets or sets the number of rows to scroll per mouse wheel tick or touch drag step.

public int ScrollMultiplier { get; set; }

Property Value

int

SelectedItem

Gets the data object associated with the currently selected row, or null if none is selected.

[Browsable(false)]
public object SelectedItem { get; }

Property Value

object

SelectedRowIndex

Gets or sets the zero-based index of the selected data row, adjusted for the header row. Returns null when no row is selected.

[Browsable(false)]
public int? SelectedRowIndex { get; set; }

Property Value

int?

SelectionBackground

Gets or sets the brush used to draw the background of selected rows.

public IBrush SelectionBackground { get; set; }

Property Value

IBrush

SelectionHoverBackground

Gets or sets the brush used to draw the background of hovered rows.

public IBrush SelectionHoverBackground { get; set; }

Property Value

IBrush

ShowGridLines

Gets or sets a value indicating whether grid lines are drawn between cells.

public bool ShowGridLines { get; set; }

Property Value

bool

SortColumn

Gets or sets the zero-based index of the column currently used for sorting, or null when no sort is applied.

[Browsable(false)]
public int? SortColumn { get; set; }

Property Value

int?

SortDirection

Gets or sets the sort direction applied to SortColumn.

[Browsable(false)]
public ListSortDirection SortDirection { get; set; }

Property Value

ListSortDirection

SortableHeaders

Gets or sets a value indicating whether clicking a header cell sorts the column. When true (default), header cells are clickable buttons that toggle sorting.

public bool SortableHeaders { get; set; }

Property Value

bool

StartRow

Gets or sets the zero-based index of the first visible data row, used for vertical scrolling.

public int StartRow { get; set; }

Property Value

int

Style

Gets the cloned DataGridStyle currently applied to this DataGrid.

public DataGridStyle Style { get; }

Property Value

DataGridStyle

TotalRows

Gets the total number of data rows loaded into the grid.

public int TotalRows { get; }

Property Value

int

VerticalAlignment

Gets or sets the vertical alignment of the widget within its parent container.

public override VerticalAlignment VerticalAlignment { get; set; }

Property Value

VerticalAlignment

Methods

ApplyStyle(WidgetStyle)

Applies the specified widget style to this widget.

protected override void ApplyStyle(WidgetStyle style)

Parameters

style WidgetStyle

The widget style to apply.

InternalArrange()

Arranges the child widgets within this widget's bounds.

protected override void InternalArrange()

InternalMeasure(Point)

Measures the widget and its children to determine the required size.

protected override Point InternalMeasure(Point availableSize)

Parameters

availableSize Point

The available size for this widget and its children.

Returns

Point

The measured size of this widget.

InternalRender(RenderContext)

Renders the widget's content (called after backgrounds and borders are rendered). Default implementation renders all child widgets.

public override void InternalRender(RenderContext context)

Parameters

context RenderContext

The render context to draw to.

InvalidateDataRow(int)

Re-evaluates the source values for the given data row and marks the visual data as needing a refresh. Call this after modifying a row's bound properties to reflect the changes in the grid display.

public void InvalidateDataRow(int rowIndex)

Parameters

rowIndex int

The zero-based index of the row in the Data collection.

OnMouseLeft()

Called when the mouse pointer leaves the widget.

public override void OnMouseLeft()

OnMouseMoved()

Called when the mouse pointer moves within the widget.

public override void OnMouseMoved()

OnMouseWheel(float)

Called when the mouse wheel is scrolled while over the widget.

public override void OnMouseWheel(float delta)

Parameters

delta float

The scroll delta value.

OnTouchDown()

Called when a touch point is pressed on the widget.

public override void OnTouchDown()

OnTouchUp()

Called when a touch point is released on the widget.

public override void OnTouchUp()

Events

SelectedIndexChanged

Occurs when the selected row index changes.

public event MyraEventHandler SelectedIndexChanged

Event Type

MyraEventHandler