Table of Contents

Class ListView

Namespace
Terminal.Gui
Assembly
Terminal.Gui.dll

ListView View renders a scrollable list of data where each item can be activated to perform an action.

public class ListView : View, IDisposable, ISupportInitializeNotification, ISupportInitialize
Inheritance
ListView
Implements
Inherited Members

Remarks

The ListView displays lists of data and allows the user to scroll through the data. Items in the can be activated firing an event (with the ENTER key or a mouse double-click). If the AllowsMarking property is true, elements of the list can be marked by the user.

By default ListView uses ToString() to render the items of any IList object (e.g. arrays, List<T>, and other collections). Alternatively, an object that implements IListDataSource can be provided giving full control of what is rendered.

ListView can display any object that implements the IList interface. string values are converted into NStack.ustring values before rendering, and other values are converted into string by calling ToString() and then converting to NStack.ustring .

To change the contents of the ListView, set the Source property (when providing custom rendering via IListDataSource) or call SetSource(IList) an IList is being used.

When AllowsMarking is set to true the rendering will prefix the rendered items with [x] or [ ] and bind the SPACE key to toggle the selection. To implement a different marking style set AllowsMarking to false and implement custom rendering.

Searching the ListView with the keyboard is supported. Users type the first characters of an item, and the first item that starts with what the user types will be selected.

Constructors

ListView()

Initializes a new instance of ListView. Set the Source property to display something.

ListView(IList)

Initializes a new instance of ListView that will display the contents of the object implementing the IList interface, with relative positioning.

ListView(IListDataSource)

Initializes a new instance of ListView that will display the provided data source, using relative positioning.

ListView(Rect, IList)

Initializes a new instance of ListView that will display the contents of the object implementing the IList interface with an absolute position.

ListView(Rect, IListDataSource)

Initializes a new instance of ListView with the provided data source and an absolute position

Properties

AllowsMarking

Gets or sets whether this ListView allows items to be marked.

AllowsMultipleSelection

If set to true more than one item can be selected. If false selecting an item will cause all others to be un-selected. The default is false.

KeystrokeNavigator

Gets the CollectionNavigator that searches the Source collection as the user types.

LeftItem

Gets or sets the leftmost column that is currently visible (when scrolling horizontally).

Maxlength

Gets the widest item in the list.

SelectedItem

Gets or sets the index of the currently selected item.

Source

Gets or sets the IListDataSource backing this ListView, enabling custom rendering.

TopItem

Gets or sets the item that is displayed at the top of the ListView.

Methods

AllowsAll()

If AllowsMarking and AllowsMultipleSelection are both true, unmarks all marked items other than the currently selected.

EnsureSelectedItemVisible()

Ensures the selected item is always visible on the screen.

MarkUnmarkRow()

Marks the SelectedItem if it is not already marked.

MouseEvent(MouseEvent)

Method invoked when a mouse event is generated

MoveDown()

Changes the SelectedItem to the next item in the list, scrolling the list if needed.

MoveEnd()

Changes the SelectedItem to last item in the list, scrolling the list if needed.

MoveHome()

Changes the SelectedItem to the first item in the list, scrolling the list if needed.

MovePageDown()

Changes the SelectedItem to the item just below the bottom of the visible list, scrolling if needed.

MovePageUp()

Changes the SelectedItem to the item at the top of the visible list.

MoveUp()

Changes the SelectedItem to the previous item in the list, scrolling the list if needed.

OnEnter(View)

Method invoked when a view gets focus.

OnLeave(View)

Method invoked when a view loses focus.

OnOpenSelectedItem()

Invokes the OpenSelectedItem event if it is defined.

OnRowRender(ListViewRowEventArgs)

Virtual method that will invoke the RowRender.

OnSelectedChanged()

Invokes the SelectedItemChanged event if it is defined.

PositionCursor()

Positions the cursor in the right position based on the currently focused view in the chain.

ProcessKey(KeyEvent)

If the view is focused, gives the view a chance to process the keystroke.

Redraw(Rect)

Redraws this view and its subviews; only redraws the views that have been flagged for a re-display.

ScrollDown(int)

Scrolls the view down by items items.

ScrollLeft(int)

Scrolls the view left.

ScrollRight(int)

Scrolls the view right.

ScrollUp(int)

Scrolls the view up by items items.

SetSource(IList)

Sets the source of the ListView to an IList.

SetSourceAsync(IList)

Sets the source to an IList value asynchronously.

Events

OpenSelectedItem

This event is raised when the user Double Clicks on an item or presses ENTER to open the selected item.

RowRender

This event is invoked when this ListView is being drawn before rendering.

SelectedItemChanged

This event is raised when the selected item in the ListView has changed.