Search Results for

Show / Hide Table of Contents

# Class TableView

View for tabular data based on a System.Data.DataTable. See TableView Deep Dive for more information.

##### Inheritance

System.Object
Responder
View
TableView

##### Implements

System.IDisposable
System.ComponentModel.ISupportInitializeNotification
System.ComponentModel.ISupportInitialize

##### Inherited Members

View.Added
View.Removed
View.Enter
View.Leave
View.MouseEnter
View.MouseLeave
View.MouseClick
View.HotKey
View.HotKeySpecifier
View.Shortcut
View.ShortcutTag
View.ShortcutAction
View.Data
View.Driver
View.Subviews
View.TabIndexes
View.TabIndex
View.TabStop
View.CanFocus
View.Id
View.IsCurrentTop
View.WantMousePositionReports
View.WantContinuousButtonPressed
View.Frame
View.LayoutStyle
View.Bounds
View.X
View.Y
View.Width
View.Height
View.SuperView
View.SetNeedsDisplay()
View.ClearLayoutNeeded()
View.SetNeedsDisplay(Rect)
View.SetChildNeedsDisplay()
View.Add(View)
View.Add(View[])
View.RemoveAll()
View.Remove(View)
View.BringSubviewToFront(View)
View.SendSubviewToBack(View)
View.SendSubviewBackwards(View)
View.BringSubviewForward(View)
View.Clear()
View.Clear(Rect)
View.ScreenToView(Int32, Int32)
View.ClipToBounds()
View.SetClip(Rect)
View.DrawFrame(Rect, Int32, Boolean)
View.DrawHotString(ustring, Attribute, Attribute)
View.DrawHotString(ustring, Boolean, ColorScheme)
View.Move(Int32, Int32)
View.HasFocus
View.OnAdded(View)
View.OnRemoved(View)
View.OnEnter(View)
View.OnLeave(View)
View.Focused
View.MostFocused
View.ColorScheme
View.AddRune(Int32, Int32, Rune)
View.ClearNeedsDisplay()
View.DrawContent
View.OnDrawContent(Rect)
View.SetFocus()
View.KeyPress
View.ProcessHotKey(KeyEvent)
View.ProcessColdKey(KeyEvent)
View.KeyDown
View.OnKeyDown(KeyEvent)
View.KeyUp
View.OnKeyUp(KeyEvent)
View.EnsureFocus()
View.FocusFirst()
View.FocusLast()
View.FocusPrev()
View.FocusNext()
View.LayoutStarted
View.LayoutComplete
View.Initialized
View.LayoutSubviews()
View.Text
View.AutoSize
View.TextAlignment
View.VerticalTextAlignment
View.TextDirection
View.IsInitialized
View.ToString()
View.OnMouseEnter(MouseEvent)
View.OnMouseLeave(MouseEvent)
View.OnMouseEvent(MouseEvent)
View.OnMouseClick(View.MouseEventArgs)
View.Dispose(Boolean)
View.BeginInit()
View.EndInit()
View.Visible
View.SetWidth(Int32, Int32)
View.SetHeight(Int32, Int32)
View.GetCurrentWidth(Int32)
View.GetCurrentHeight(Int32)
Responder.Dispose()
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()

Initialzies a TableView class using Computed layout. Set the Table property to begin editing

##### Declaration

    public TableView()

#### TableView(DataTable)

Initialzies a TableView class using Computed layout.

##### 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

Responder.MouseEvent(MouseEvent)

#### 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

View.PositionCursor()

#### ProcessKey(KeyEvent)

##### Declaration

    public override bool ProcessKey(KeyEvent keyEvent)

##### Parameters

Type | Name | Description
--- | --- | ---
KeyEvent | keyEvent |

##### Returns

Type | Description
--- | ---
System.Boolean |

##### Overrides

View.ProcessKey(KeyEvent)

#### Redraw(Rect)

##### Declaration

    public override void Redraw(Rect bounds)

##### Parameters

Type | Name | Description
--- | --- | ---
Rect | bounds |

##### Overrides

View.Redraw(Rect)

#### 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()

Updates the view to reflect changes to Table and to (ColumnOffset / RowOffset) etc

##### 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