Form

GPALListView

Everything on Settings Every Control Takes applies here too. GPAL.ListView builds one. WithColumns names the columns and WithView picks the mode, Details, List, LargeIcon, SmallIcon or Tile, where Details is the one that shows columns.

WithColumnWidth takes pixel widths in column order, or shares as doubles, in which case the columns reflow as the form resizes. The widths are worked out whole: a column nobody named takes an equal share of what the named ones left, named widths wider than the control are scaled down together so every column stays visible, and the last column takes the remainder so the row ends at the edge. Naming nothing at all gives equal columns. WithColumnWeight gives one column a share.

WithSortable lets a click on a header sort the rows. WithCheckBoxes puts a checkbox on every row and WithFullRowSelect makes a click anywhere in a row select it. WithMultiSelect allows more than one row selected.

AddItem adds a row, one value per column. DisableItem greys a row and EnableItem restores it. CheckedItems and SelectedItems each answer a read-only list of bool, one per row, so ticking and selection are read separately. ItemChecked and SelectedIndexChanged are the events to hang a handler on. GPAL.ListViewFor(columns) is the shorthand.

NOTE

The layout runs when the control can first measure itself, when a tab it sits on is first shown, and when it is resized. It does not run as rows are added: a column that re-measures itself while data flows in is a column that moves while it is being read. A horizontal scrollbar is never the answer either, so widths that do not fit are scaled rather than clipped, with a floor of 24 pixels a column so a squeeze cannot make one unclickable.

WARNING

In Details view a list view shows one line a row, whatever it is told, and a value longer than its column is cut off rather than wrapped. There is no setting for it. Where the text is a sentence, a message or a path, use GPALDataGridView and its WithWrap instead.

Examples

GPAL Fluent: High-level fluent C# API

//Shares and pixel widths are two overloads of the same call: doubles reflow with the form, ints hold their size and the last column takes whatever the others leave. CheckedItems and SelectedItems are parallel to the rows, so index 2 in either is the third row.

GPALListView files = (GPALListView)GPAL.ListView

.WithColumns("File", "Size", "Status")

.WithColumnWidth(0.5, 0.2, 0.3)

.WithCheckBoxes()

.WithFullRowSelect(true)

.WithSortable()

.WithName("files");


files.AddItem("File1.txt", "2.5 MB", "Done");

files.AddItem("File2.pdf", "1.8 MB", "Pending");

files.AddItem("File3.lock", "0 KB", "Locked by another run");


// the row stays visible so it can say why it is out

files.DisableItem(2);


// which rows the user ticked, and which row is highlighted

IReadOnlyList<bool> ticked = files.CheckedItems;

IReadOnlyList<bool> selected = files.SelectedItems;

💬 Ask GPAL