ListView - ahatornn/clforms GitHub Wiki

ListView

ClForms.Elements.ListView
Represents a Windows list view control, which displays a collection of items that can be displayed like a table

public class ListView: ListView<object>, IElementStyle<ListView>

Inheritance Control -> BaseFocusableControl -> ListView<T> -> ListView
Derived IElementStyle<ListView>

ListView is derived from ListView<T> where T defines the type of item in the list. For a ListView, this type is object. You can use ListView<T> with the desired type T to get the items immediately in the needed type

Examples

The following code example creates a ListView control with three Item objects. The example also creates ColumnHeader objects to display the details view.

var targetListView = new ListView<CountryInfo>()
{
    ShowGridLine = true,
    ShowSummary = true,
    BorderColor = Color.Black,
    SummaryText = "Use [Tab], [↓] or [↑]",
    Text = "Counties",
    TextAlignment = TextAlignment.Center,
    AutoSelect = true,
    HeaderForeground = Color.Cyan,
};
targetListView.Items.AddRange(MainWindow.CountryInfos);
targetListView.ColumnHeaders.Add("Country", x => x.Country);
targetListView.ColumnHeaders.Add("Gdp", x => x.Gdp.ToString(), width: 6, TextAlignment.Right);
targetListView.ColumnHeaders.Add("Ppl", x => x.Population.ToString(), width: 9, TextAlignment.Right);
targetListView.OnItemDraw += TargetListViewItemDraw;private void TargetListViewItemDraw(object sender, ListBoxItemStyleEventArgs<CountryInfo> e)
{
    if (targetListView.Items.IndexOf(e.Item) % 2 == 0)
    {
        e.Foreground = Color.White;
    }
}

You can find more examples of using the Label in this project

Remarks

You can use the ListView control in a variety of ways. The control can be used to display information from an application, a database, or a text file. The ListView can also be used to obtain information from the user, such as selecting a set of files to process. ListView provides a large number of properties that provide flexibility in appearance and behavior.

Constructors

Syntax Description
ListView() Initialize a new instance ListView

Properties

Name Type Description
AutoSelect bool Gets or sets a value indicating whether set SelectedIndex to first visible item after component focused if current SelectedIndex value is -1
AutoSize bool Gets or sets a value indicating whether the control is resized in accordance with its contents
Background Color Gets or sets a brush that describes the background of a control
BackgroundIsTransparent bool Gets a value indicating whether the Background has Color.NotSet
BorderChars GridSpanBorderChars Gets or sets a value of border chars
BorderColor Color Gets or sets a value of the grid border
Bounds Rect Gets the size and location of the control including its nonclient elements, in points, relative to the parent control
ColumnHeaders ColumnHeaderCollection<object> Gets the collection of all column headers that appear in the control
Columns int Gets or sets the number of columns in the switch group
DesiredSize Size Gets the size that this element computed during the measure pass of the layout process
DisabledBackground Color Gets or sets a value to display of background when the control is disabled
DisabledForeground Color Gets or sets a value to display of text color when the control is disabled
DrawingContext IDrawingContext Gets a value of the drawing context
FirstVisibleItemIndex int Gets the index of first visible item
FocusBackground Color Focused component background color
FocusForeground Color Focused component text color
Foreground Color Gets or sets a brush that describes the text of a control
ForegroundIsTransparent bool Gets a value indicating whether the Foreground has Color.NotSet
HeaderForeground Color Gets or sets a color that describes the foreground of a control headers
Height int? Gets or sets the height of the control
Id long Gets a value of the control's identifier
IsDisabled bool Gets or sets a value indicating whether the control cannot respond to user interaction
IsFocus bool Gets or sets focus value of component
IsMeasureValid bool Gets a value indicating whether component sizing was performed
IsVisualValid bool Gets a value indicating whether the component is being re-rendered
Items ListViewItemCollection<object> Gets a collection containing all items in the control
Location Point Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container
Margin Thickness Gets or sets the outer margin of an element
Padding Thickness Gets or sets a Thickness value that describes the amount of space between a control and its child element
Parent ContentControl Gets or sets the parent container of the control
SelectedIndex int Gets or sets the index of the selected item in a ListView control
ShowGridLine bool Gets or sets a value indicating whether grid lines appear between the columns containing the items in the control
ShowSummary bool Gets or sets a value indicating whether show summary area for SummaryText
SummaryText string Gets or sets the summary text in the bottom of control
TabIndex int Gets or sets the sequence for moving the TAB key between the controls inside the container
TabStop bool Gets or sets a value indicating whether the user can focus on the given control using the TAB key
Tag object Gets or sets the object that contains data about the control
Text string Gets or sets the text associated with this control
TextAlignment TextAlignment Gets or sets the horizontal alignment of the text associated with this control
VisibleItems IEnumerable<object> Gets the all visible items
Width int? Gets or sets the width of the control

Methods

Syntax Description
Arrange(Rect) Positions child elements and determines a size for a Control. Parent elements call this method from their Arrange(Rect) implementation to form a recursive layout update
CanFocus() Indicates whether component focus can be set
InputAction(ConsoleKeyInfo) Handles a keystroke
InvalidateMeasure() Invalidates the measurement state (layout) for the element
InvalidateMeasureIfAutoSize() Invalidates the measurement state (layout) for the element if AutoSize property is true otherwise invalidates the rendering of the element
InvalidateVisual() Invalidates the rendering of the element, and forces a complete new layout pass. OnRender(IDrawingContext) is called after the layout cycle is completed
Measure(Size) Updates DesiredSize of a Control. Parent elements call this method from their own Measure(Size) implementations to form a recursive layout update
OnRender(IDrawingContext) Filling a pseudographics drawing context
ParentWindow() Gets the form the control is in
SetFocus() Sets input focus to current item
SetStyle(Action) Defines actions with an element style

Events

Event Description
OnAutoSelectChanged Occurs when the value of the AutoSelect property changes
OnAutoSizeChanged Occurs when the value of the AutoSize property changes
OnBackgroundChanged Occurs when the value of the Background property changes
OnBorderCharsChanged Occurs when the value of the BorderChars property changes
OnBorderColorChanged Occurs when the value of the BorderColor property changes
OnColumnsChanged Occurs when the value of the property changes
OnDisabledBackgroundChanged Occurs when the value of the DisabledBackground property changes
OnDisabledChanged Occurs when the value of the IsDisabled property changes
OnDisabledForegroundChanged Occurs when the value of the DisabledForeground property changes
OnEnter Input focus event
OnFocusBackgroundChanged Occurs when the value of the FocusBackground property changes
OnFocusChanged Occurs when the value of the IsFocus property changes
OnFocusForegroundChanged Occurs when the value of the FocusForeground property changes
OnForegroundChanged Occurs when the value of the Foreground property changes
OnHeaderForegroundChanged Occurs when the value of the HeaderForeground property changes
OnHeightChanged Occurs when the value of the Height property changes
OnItemClick Occurs when clicked on selected item
OnItemDraw Occurs when the any items will draw
OnItemDrawing Occurs when the any items drawing
OnLeave Input focus loss event
OnMarginChanged Occurs when the value of the Margin property changes
OnPaddingChanged Occurs when the value of the Padding property changes
OnParentChanged Occurs when the value of the Parent property changes
OnSelectedIndexChanged Occurs when the value of the SelectedIndex property changes
OnShowGridLineChanged Occurs when the value of the ShowGridLine property changes
OnShowSummaryChanged Occurs when the value of the ShowSummary property changes
OnSummaryTextChanged Occurs when the value of the SummaryText property changes
OnTabIndexChanged Occurs when a property value of TabIndex changes
OnTabStopChanged Occurs when a property value of TabStop changes
OnTagChanged Occurs when the value of the Tag property changes
OnTextAlignmentChanged Occurs when the value of the TextAlignment property changes
OnTextChanged Occurs when the value of the Text property changes
OnWidthChanged Occurs when the value of the Width property changes
⚠️ **GitHub.com Fallback** ⚠️