Farbschema: Dunkel
Sie befinden sich hier: start » en » Documentation » Microsoft Access development tools » WKL Forms Object Library » Data views » WklTreeView

WklTreeView

A data-bound tree for Access forms. It shows the records of a table, query, or SQL statement as a hierarchy, lets users select, search, edit, and move them, and writes changes back to the data source just like a bound Access control.

Get started

Common tasks

Visual aid

+- Tree1 -------------------------------+
| [1] Search: Ca_       2 matches  < >  |
+---------------------------------------+
| v [F] United States             [2]   |
|   v [F] California                    |
|       [D] Los Angeles   <-- [3]       |
|       [D] San Francisco               |
|   > [F] Texas                         |
| > [F] Canada                          |
+---------------------------------------+
RegionMeaning
1Search bar (Ctrl+F, AllowSearch): search text, number of matches, previous/next, „Matches only“
2One node per record: text from TextField, symbol ([F] folder, [D] document) from ImageField or DefaultImage, children from ParentField; v expanded, > collapsed
3Selected node (SelectedKey); right-click opens the context menu

Key features

  • Binding without code: RecordSource, KeyField, ParentField, TextField; optional fields for sort order, symbol, tooltip, check mark, color, and bold text.
  • Lazy loading of large or linked tables: each level is read only when it's expanded.
  • Master-detail like an Access subform (LinkChildFields, LinkMasterFields): the master is the form's current record, any DAO or ADO recordset, or values from code, including on UserForms.
  • Composite keys: KeyField and ParentField with several fields; in VBA, such keys are arrays.
  • Editing with write-back in a single transaction per operation: rename (F2), add (Insert), delete (Delete), move and copy by dragging or Ctrl+X/C/V, check marks.
  • Search and filter across the whole data source, including nodes that haven't been loaded.
  • Paths and JPath: select a node by text path (United States\California\Los Angeles) or find nodes with a JPath expression.
  • State: save and restore the nodes and view state as JSON or XML (file, string, ADODB.Stream, JDoc), or just the view (Layout).
  • Access conventions: a property sheet with value lists, a designer window with live preview, events in the form module with Cancel, KeyCode = 0, and Response, and fixed error numbers.

Core concepts

Binding. Each record is a node. KeyField identifies it, and ParentField holds the key of its parent. A record whose parent doesn't exist (Null, 0, or an unknown key) becomes a root node. The control reads data through DAO in the hosting Access instance, so linked tables and queries with form references work just as they do on any form.

Keys. Every member and event identifies a node by its key: a Variant with the data type of the key field, or, with several key fields, an array with one value per field.

User actions and code. Events report what the user does. The same operations called from code (MoveNode, DeleteNode, NodeText = …) raise no events, just as code doesn't raise AfterUpdate in Access, but they write through the same transaction.

AutoSave. With AutoSave = True (the default), every change is written immediately; BeforeUpdate can cancel it, which rolls back the entire operation. With AutoSave = False, or when the tree was loaded from a recordset or a file, only the display changes.

Design view. With LivePreview = False (the default), design view shows a sample tree and never queries the data source; with True, it shows the real nodes.

Administration

Troubleshooting

For developers

en/wiki/msaccess/comctl/data-views/treeview/start.txt · Zuletzt geändert: von Wolfgang van der Stille