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, IDesignable
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 ObservableCollection<T> 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 string values before rendering, and other values are converted into string by calling ToString() and then converting to string .

To change the contents of the ListView, set the Source property (when providing custom rendering via IListDataSource) or call SetSource<T>(ObservableCollection<T>) 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.

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 index of the item that will appear at the top of the Viewport.

Methods

Dispose(bool)

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

EnableForDesign()

Causes the View to enable design-time mode. This typically means that the view will load demo data and be configured to allow for design-time manipulation.

EnsureSelectedItemVisible()

Ensures the selected item is always visible on the screen.

MarkAll(bool)

If AllowsMarking and AllowsMultipleSelection are both true, marks all items.

MarkUnmarkSelectedItem()

Marks the SelectedItem if it is not already marked.

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.

OnCollectionChanged(NotifyCollectionChangedEventArgs)

Call the event to raises the CollectionChanged.

OnDrawingContent()

Called when the View's content is to be drawn. The default implementation does nothing.

OnFrameChanged(in Rectangle)

Called when Frame changes.

OnHasFocusChanged(bool, View, View)

Invoked after HasFocus has changed. This method is called before the HasFocusChanged event is raised.

OnKeyDown(Key)

Called when the user presses a key, allowing subscribers to pre-process the key down event. Called before key bindings are invoked and KeyDownNotHandled is raised. Set Handled to true to stop the key from being processed further.

OnMouseEvent(MouseEventArgs)

Called when a mouse event occurs within the view's Viewport.

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.

OnViewportChanged(DrawEventArgs)

Called when the Viewport changes. Invokes the ViewportChanged event.

ResumeSuspendCollectionChangedEvent()

Allow resume the CollectionChanged event from being invoked,

SetSourceAsync<T>(ObservableCollection<T>)

Sets the source to an IList value asynchronously.

SetSource<T>(ObservableCollection<T>)

Sets the source of the ListView to an IList.

SuspendCollectionChangedEvent()

Allow suspending the CollectionChanged event from being invoked,

UnmarkAllButSelected()

If AllowsMarking and AllowsMultipleSelection are both true, unmarks all marked items other than SelectedItem.

Events

CollectionChanged

Event to raise when an item is added, removed, or moved, or the entire list is refreshed.

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.