Class TableView
View for tabular data based on a System.Data.DataTable.
See TableView Deep Dive for more information.
Implements
System.IDisposable
System.ComponentModel.ISupportInitializeNotification
System.ComponentModel.ISupportInitialize
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: Terminal.Gui
Assembly: Terminal.Gui.dll
Syntax
public class TableView : View, IDisposable, ISupportInitializeNotification, ISupportInitialize
Constructors
TableView()
Declaration
public TableView()
TableView(DataTable)
Declaration
public TableView(DataTable table)
Parameters
Type | Name | Description |
---|---|---|
System.Data.DataTable | table | The table to display in the control |
Fields
DefaultMaxCellWidth
The default maximum cell width for MaxCellWidth and MaxWidth
Declaration
public const int DefaultMaxCellWidth = 100
Field Value
Type | Description |
---|---|
System.Int32 |
Properties
CellActivationKey
The key which when pressed should trigger CellActivated event. Defaults to Enter.
Declaration
public Key CellActivationKey { get; set; }
Property Value
Type | Description |
---|---|
Key |
ColumnOffset
Horizontal scroll offset. The index of the first column in Table to display when when rendering the view.
Declaration
public int ColumnOffset { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Remarks
This property allows very wide tables to be rendered with horizontal scrolling
FullRowSelect
True to select the entire row at once. False to select individual cells. Defaults to false
Declaration
public bool FullRowSelect { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
MaxCellWidth
The maximum number of characters to render in any given column. This prevents one long column from pushing out all the others
Declaration
public int MaxCellWidth { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
MultiSelect
True to allow regions to be selected
Declaration
public bool MultiSelect { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
MultiSelectedRegions
When MultiSelect is enabled this property contain all rectangles of selected cells. Rectangles describe column/rows selected in Table (not screen coordinates)
Declaration
public Stack<TableView.TableSelection> MultiSelectedRegions { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.Stack<TableView.TableSelection> |
NullSymbol
The text representation that should be rendered for cells with the value System.DBNull.Value
Declaration
public string NullSymbol { get; set; }
Property Value
Type | Description |
---|---|
System.String |
RowOffset
Vertical scroll offset. The index of the first row in Table to display in the first non header line of the control when rendering the view.
Declaration
public int RowOffset { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
SelectedColumn
The index of System.Data.DataTable.Columns in Table that the user has currently selected
Declaration
public int SelectedColumn { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
SelectedRow
The index of System.Data.DataTable.Rows in Table that the user has currently selected
Declaration
public int SelectedRow { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
SeparatorSymbol
The symbol to add after each cell value and header value to visually seperate values (if not using vertical gridlines)
Declaration
public char SeparatorSymbol { get; set; }
Property Value
Type | Description |
---|---|
System.Char |
Style
Contains options for changing how the table is rendered
Declaration
public TableView.TableStyle Style { get; set; }
Property Value
Type | Description |
---|---|
TableView.TableStyle |
Table
The data table to render in the view. Setting this property automatically updates and redraws the control.
Declaration
public DataTable Table { get; set; }
Property Value
Type | Description |
---|---|
System.Data.DataTable |
Methods
CellToScreen(Int32, Int32)
Returns the screen position (relative to the control client area) that the given cell is rendered or null if it is outside the current scroll area or no table is loaded
Declaration
public Point? CellToScreen(int tableColumn, int tableRow)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | tableColumn | The index of the Table column you are looking for, use System.Data.DataColumn.Ordinal |
System.Int32 | tableRow | The index of the row in Table that you are looking for |
Returns
Type | Description |
---|---|
System.Nullable<Point> |
ChangeSelectionByOffset(Int32, Int32, Boolean)
Moves the SelectedRow and SelectedColumn by the provided offsets. Optionally starting a box selection (see MultiSelect)
Declaration
public void ChangeSelectionByOffset(int offsetX, int offsetY, bool extendExistingSelection)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | offsetX | Offset in number of columns |
System.Int32 | offsetY | Offset in number of rows |
System.Boolean | extendExistingSelection | True to create a multi cell selection or adjust an existing one |
EnsureSelectedCellIsVisible()
Updates scroll offsets to ensure that the selected cell is visible. Has no effect if Table has not been set.
Declaration
public void EnsureSelectedCellIsVisible()
Remarks
Changes will not be immediately visible in the display until you call SetNeedsDisplay()
EnsureValidScrollOffsets()
Updates ColumnOffset and RowOffset where they are outside the bounds of the table (by adjusting them to the nearest existing cell). Has no effect if Table has not been set.
Declaration
public void EnsureValidScrollOffsets()
Remarks
Changes will not be immediately visible in the display until you call SetNeedsDisplay()
EnsureValidSelection()
Updates SelectedColumn, SelectedRow and MultiSelectedRegions where they are outside the bounds of the table (by adjusting them to the nearest existing cell). Has no effect if Table has not been set.
Declaration
public void EnsureValidSelection()
Remarks
Changes will not be immediately visible in the display until you call SetNeedsDisplay()
GetAllSelectedCells()
Returns all cells in any MultiSelectedRegions (if MultiSelect is enabled) and the selected cell
Declaration
public IEnumerable<Point> GetAllSelectedCells()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<Point> |
IsSelected(Int32, Int32)
Returns true if the given cell is selected either because it is the active cell or part of a multi cell selection (e.g. FullRowSelect)
Declaration
public bool IsSelected(int col, int row)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | col | |
System.Int32 | row |
Returns
Type | Description |
---|---|
System.Boolean |
MouseEvent(MouseEvent)
Declaration
public override bool MouseEvent(MouseEvent me)
Parameters
Type | Name | Description |
---|---|---|
MouseEvent | me |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
OnCellActivated(TableView.CellActivatedEventArgs)
Invokes the CellActivated event
Declaration
protected virtual void OnCellActivated(TableView.CellActivatedEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
TableView.CellActivatedEventArgs | args |
OnSelectedCellChanged(TableView.SelectedCellChangedEventArgs)
Invokes the SelectedCellChanged event
Declaration
protected virtual void OnSelectedCellChanged(TableView.SelectedCellChangedEventArgs args)
Parameters
Type | Name | Description |
---|---|---|
TableView.SelectedCellChangedEventArgs | args |
PositionCursor()
Positions the cursor in the area of the screen in which the start of the active cell is rendered. Calls base implementation if active cell is not visible due to scrolling or table is loaded etc
Declaration
public override void PositionCursor()
Overrides
ProcessKey(KeyEvent)
Declaration
public override bool ProcessKey(KeyEvent keyEvent)
Parameters
Type | Name | Description |
---|---|---|
KeyEvent | keyEvent |
Returns
Type | Description |
---|---|
System.Boolean |
Overrides
Redraw(Rect)
Declaration
public override void Redraw(Rect bounds)
Parameters
Type | Name | Description |
---|---|---|
Rect | bounds |
Overrides
RenderCell(Attribute, String, Boolean)
Override to provide custom multi colouring to cells. Use Driver to
with AddStr(ustring). The driver will already be
in the correct place when rendering and you must render the full
render
or the view will not look right. For simpler provision of color use ColorGetter
For changing the content that is rendered use RepresentationGetter
Declaration
protected virtual void RenderCell(Attribute cellColor, string render, bool isPrimaryCell)
Parameters
Type | Name | Description |
---|---|---|
Attribute | cellColor | |
System.String | render | |
System.Boolean | isPrimaryCell |
ScreenToCell(Int32, Int32)
Returns the column and row of Table that corresponds to a given point on the screen (relative to the control client area). Returns null if the point is in the header, no table is loaded or outside the control bounds
Declaration
public Point? ScreenToCell(int clientX, int clientY)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | clientX | X offset from the top left of the control |
System.Int32 | clientY | Y offset from the top left of the control |
Returns
Type | Description |
---|---|
System.Nullable<Point> |
SelectAll()
When MultiSelect is on, creates selection over all cells in the table (replacing any old selection regions)
Declaration
public void SelectAll()
SetSelection(Int32, Int32, Boolean)
Moves the SelectedRow and SelectedColumn to the given col/row in Table. Optionally starting a box selection (see MultiSelect)
Declaration
public void SetSelection(int col, int row, bool extendExistingSelection)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | col | |
System.Int32 | row | |
System.Boolean | extendExistingSelection | True to create a multi cell selection or adjust an existing one |
Update()
Declaration
public void Update()
Remarks
This always calls SetNeedsDisplay()
Events
CellActivated
This event is raised when a cell is activated e.g. by double clicking or pressing CellActivationKey
Declaration
public event Action<TableView.CellActivatedEventArgs> CellActivated
Event Type
Type | Description |
---|---|
System.Action<TableView.CellActivatedEventArgs> |
SelectedCellChanged
This event is raised when the selected cell in the table changes.
Declaration
public event Action<TableView.SelectedCellChangedEventArgs> SelectedCellChanged
Event Type
Type | Description |
---|---|
System.Action<TableView.SelectedCellChangedEventArgs> |
Implements
System.IDisposable
System.ComponentModel.ISupportInitializeNotification
System.ComponentModel.ISupportInitialize