Skip to content

ObservableTable Public Methods

Haruki Takahashi edited this page May 30, 2023 · 1 revision

Constructors

Initialize a new ObservableTable with no column headers and no records (rows).

public ObservableTable<T>()

Initialize a new ObservableTable with the given column headers and records.

public ObservableTable(IEnumerable<T> headers, IEnumerable<IList<T?>> records)
public ObservableTable(IEnumerable<T> headers, params IList<T?>[] records)

Events

While technically not a method, ObservableTable offers the following event:

public event EventHandler? TableModified

It is triggered after any of the following methods are invoked. Event arguments are not implemented currently.


Rows

Rows can be accessed by ObservableTable.Records[index]. Only modify rows with the following methods.

Insert Rows

Insert rows after position index.

public void InsertRow(int index, IEnumerable<IList<T?>> rows)
public void InsertRow(int index, params IList<T?>[] rows)

Remove rows

public void RemoveRow(IEnumerable<ObservableCollection<T?>> rows)
public void RemoveRow(params ObservableCollection<T?>[] rows)

Move a row

Move row oldIndex to newIndex

public void ReorderRow(int oldIndex, int newIndex)

Columns

Columns cannot be accessed directly. Only modify columns with the following methods.

Insert columns

Insert columns after index

public void InsertColumn(int index, params Column<T>[] columns)
public void InsertColumn(int index, IEnumerable<Column<T>> columns)

Remove columns

public void RemoveColumn(IEnumerable<T> headers)
public void RemoveColumn(params T[] headers)

Move a column

Move column oldIndex to newIndex

public void ReorderColumn(int oldIndex, int newIndex)

Rename a column

Rename column index to header

public void RenameColumn(int index, T header)

Cells

Cells can be accessed directly by ObservableTable.Records[row][column].

Set cell content

public void SetCell(IEnumerable<Cell<T>> cells)
public void SetCell(params Cell<T>[] cells)

It is also possible to change the cell content by

ObservableTable.Records[row][column] = <new content>;

However, it is recommended that the SetCell methods be prioritized. Use the assignment statement for external code that you do not maintain exclusively (e.g. a DataGrid).


History

Undo/Redo

public void Undo()
public void Redo()

Undo/redo the previous transaction. Rows and columns added through the constructor cannot be undone/redone. If the initial records must be undo-able, obtain a new instance of ObservableTable using the empty constructor, then manually invoke the InsertColumns and InsertRows methods.

ObservableTable exposes two properties, undoCount and redoCount, that shows how many operations can be undone/redone.