Show / Hide Table of Contents

# Class ListView

ListView widget renders a list of data.

##### Inheritance

System.Object
Responder
View
ListView

##### Inherited Members

Responder.CanFocus
View.Add(View)
View.Add(View[])
View.AddRune(Int32, Int32, Rune)
View.Bounds
View.ChildNeedsDisplay()
View.Clear()
View.Clear(Rect)
View.ClearNeedsDisplay()
View.ClipToBounds()
View.ColorScheme
View.DrawFrame(Rect, Int32, Boolean)
View.DrawHotString(ustring, Boolean, ColorScheme)
View.DrawHotString(ustring, Attribute, Attribute)
View.Driver
View.EnsureFocus()
View.Focused
View.FocusFirst()
View.FocusLast()
View.FocusNext()
View.FocusPrev()
View.Frame
View.GetEnumerator()
View.HasFocus
View.Height
View.Id
View.LayoutStyle
View.LayoutSubviews()
View.MostFocused
View.Move(Int32, Int32)
View.ProcessColdKey(KeyEvent)
View.ProcessHotKey(KeyEvent)
View.Remove(View)
View.RemoveAll()
View.ScreenToView(Int32, Int32)
View.SetClip(Rect)
View.SetFocus(View)
View.SetNeedsDisplay()
View.SetNeedsDisplay(Rect)
View.Subviews
View.SuperView
View.ToString()
View.WantMousePositionReports
View.Width
View.X
View.Y

###### Namespace: Terminal.Gui

###### Assembly: Terminal.Gui.dll

##### Syntax

    public class ListView : Terminal.Gui.View

##### Remarks

The ListView displays lists of data and allows the user to scroll through the data and optionally mark elements of the list (controlled by the AllowsMark property).

The ListView can either render an arbitrary IList object (for example, arrays, List and other collections) which are drawn by drawing the string/ustring contents or the result of calling ToString(). Alternatively, you can provide you own IListDataSource object that gives you full control of what is rendered.

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

If you must change the contents of the ListView, set the Source property (when you are providing your own rendering via the IListDataSource implementation) or call SetSource when you are providing an IList.

### Constructors

#### ListView()

Initializes a new instance of the ListView class. You must set the Source property for this to show something.

##### Declaration

    public ListView ();

#### ListView(IList)

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

##### Declaration

    public ListView (System.Collections.IList source);

##### Parameters

Type | Name | Description
--- | --- | ---
System.Collections.IList | source | An IList data source, if the elements of the IList are strings or ustrings, the string is rendered, otherwise the ToString() method is invoked on the result.

#### ListView(IListDataSource)

Initializes a new ListView that will display the provided data source, uses relative positioning.

##### Declaration

    public ListView (Terminal.Gui.IListDataSource source);

##### Parameters

Type | Name | Description
--- | --- | ---
IListDataSource | source | IListDataSource object that provides a mechanism to render the data. The number of elements on the collection should not change, if you must change, set the "Source" property to reset the internal settings of the ListView.

#### ListView(Rect, IList)

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

##### Declaration

    public ListView (Terminal.Gui.Rect rect, System.Collections.IList source);

##### Parameters

Type | Name | Description
--- | --- | ---
Rect | rect | Frame for the listview.
System.Collections.IList | source | An IList data source, if the elements of the IList are strings or ustrings, the string is rendered, otherwise the ToString() method is invoked on the result.

#### ListView(Rect, IListDataSource)

Initializes a new ListView that will display the provided data source with an absolute position

##### Declaration

    public ListView (Terminal.Gui.Rect rect, Terminal.Gui.IListDataSource source);

##### Parameters

Type | Name | Description
--- | --- | ---
Rect | rect | Frame for the listview.
IListDataSource | source | IListDataSource object that provides a mechanism to render the data. The number of elements on the collection should not change, if you must change, set the "Source" property to reset the internal settings of the ListView.

### Properties

#### AllowsMarking

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

##### Declaration

    public bool AllowsMarking { get; set; }

##### Property Value

Type | Description
--- | ---
System.Boolean | `true` if allows marking elements of the list; otherwise, `false`.

#### SelectedItem

Gets or sets the currently selecteded item.

##### Declaration

    public int SelectedItem { get; set; }

##### Property Value

Type | Description
--- | ---
System.Int32 | The selected item.

#### Source

Gets or sets the IListDataSource backing this view, use SetSource() if you want to set a new IList source.

##### Declaration

    public Terminal.Gui.IListDataSource Source { get; set; }

##### Property Value

Type | Description
--- | ---
IListDataSource | The source.

#### TopItem

Gets or sets the item that is displayed at the top of the listview

##### Declaration

    public int TopItem { get; set; }

##### Property Value

Type | Description
--- | ---
System.Int32 | The top item.

### Methods

#### MouseEvent(MouseEvent)

##### Declaration

    public override bool MouseEvent (Terminal.Gui.MouseEvent me);

##### Parameters

Type | Name | Description
--- | --- | ---
MouseEvent | me | To be added.

##### Returns

Type | Description
--- | ---
System.Boolean | To be added.

#### PositionCursor()

Positions the cursor in this view

##### Declaration

    public override void PositionCursor ();

#### ProcessKey(KeyEvent)

Handles cursor movement for this view, passes all other events.

##### Declaration

    public override bool ProcessKey (Terminal.Gui.KeyEvent kb);

##### Parameters

Type | Name | Description
--- | --- | ---
KeyEvent | kb | Keyboard event.

##### Returns

Type | Description
--- | ---
System.Boolean | `true`, if key was processed, `false` otherwise.

#### Redraw(Rect)

Redraws the ListView

##### Declaration

    public override void Redraw (Terminal.Gui.Rect region);

##### Parameters

Type | Name | Description
--- | --- | ---
Rect | region | Region.

#### SetSource(IList)

Sets the source to an IList value, if you want to set a full IListDataSource, use the Source property.

##### Declaration

    public void SetSource (System.Collections.IList source);

##### Parameters

Type | Name | Description
--- | --- | ---
System.Collections.IList | source | To be added.

### Events

#### SelectedChanged

This event is raised when the cursor selection has changed.

##### Declaration

    public event Action SelectedChanged;

##### Event Type

Type | Description
--- | ---
System.Action | To be added.