How to: Define columns and bands
Show record source fields as columns in a tree list, group them under multilevel headers, and spread a record across several rows.
Requires WKL Forms Object Library 1.23 or later.
Solution overview
Columns.Add(FieldName, Caption, Band) creates a column, and its properties set the width,
format, alignment, editor, sorting, and total. Bands.Add(Name, Caption, ParentBand) creates a
header above a group of columns; nested bands create multilevel headers. WklColumn.RowIndex
places a column in a second row of the record. When you set up the definition in Design view, it's
saved with the form (ColumnLayout); the designer's Columns and Bands pages edit the same
objects.
Implementation
With Me!List1.Object
.Columns.Clear
.Bands.Clear
.Bands.Add "Order", "Order"
.Bands.Add "Amounts", "Amounts", "Order" ' nested below "Order"
.Columns.Add("ItemName", "Item").Width = 2600 ' 1,440 twips = 1 inch
With .Columns.Add("Quantity", "Qty", "Amounts")
.Alignment = walRight
.Summary = wsuSum
End With
With .Columns.Add("Price", "Price", "Amounts")
.Format = "Currency"
.SortDirection = wsdDescending ' siblings ordered by price
End With
With .Columns.Add("Note", "Note", "Order")
.RowIndex = 1 ' second row of each record
End With
.TreeColumn = "ItemName"
.ShowFooter = True
.BestFitColumns
End With
Dim c As WklColumn
For Each c In Me!List1.Object.Columns
Debug.Print c.Name, c.Caption, c.Width
Next
Remarks
- A column's name is its field name;
CellValue,CellText, and the events identify columns by this name. Formataccepts Access format names in English or German (Currency/Währung,Short Date/Datum, kurz) and custom formats such as#,##0.00.- Without
TreeColumn, the first visible column contains the tree. - Users can resize and move columns and sort by clicking a header;
ColumnResize,ColumnMove, andColumnClickreport these actions, andCancelinColumnClickprevents sorting. - Changes made at run time aren't saved with the form. To keep a user's layout, save
ColumnLayoutand assign it back later.
Related topics
en/wiki/msaccess/comctl/how-to/define-columns-and-bands.txt · Zuletzt geändert: von Wolfgang van der Stille