Skip to main content
The TDBTree component (from TeeDBTre.pas) connects TeeTree to database tables and queries, automatically creating tree structures from your data. This guide covers all database binding scenarios.

Understanding TDBTree

TDBTree is a specialized tree component that:
  • Automatically creates nodes from database records
  • Supports parent-child relationships via fields
  • Handles master-detail datasets
  • Allows multiple dataset levels with Layout collections
  • Updates dynamically when data changes
TDBTree inherits from TCustomTree, so all standard tree features are available.

Basic Database Binding

Required Properties

Situation 1: Parent-Child Relationships

When your table has Code and Parent fields defining the hierarchy:

Data Structure

Configuration

Result Tree

Multiple Text Fields

Display multiple fields in each node:

Situation 2: Group By Field

When your data doesn’t have explicit parent-child fields, use a field to group by:

Data Structure

Configuration

Result Tree

Expanding First Group

Situation 3: Master-Detail Relationships

Display related data from two linked datasets:

Data Structure

Master Table (Employees):
Detail Table (Salaries):

Configuration

Result Tree

Ensure the master-detail relationship is properly configured in your dataset components (MasterSource, MasterFields properties).

Advanced: Multiple Dataset Levels

For complex hierarchies with more than two dataset levels, use the Layout collection:

Layout Collection

Example: Three-Level Hierarchy

Display Modes

Control how field data is displayed:

Formatting Database Nodes

Per-Layout Formatting

Header Formatting

Refreshing the Tree

1

Manual Refresh

Call Refresh after data changes:
2

Automatic Refresh

Respond to dataset events:

Working with Database Nodes

Accessing Data

Each node can be linked back to its source record:

Node Click Events

Performance Optimization

For very large datasets, consider loading nodes on-demand:

Database Wizard

TeeTree includes a Database Wizard dialog for visual configuration:
The wizard helps configure:
  • DataSet selection
  • Field mappings
  • Master-detail relationships
  • Layout options
  • Node formatting

Common Patterns

Troubleshooting

Common Issues:
  1. Empty Tree: Ensure DataSet is Open before calling Refresh
  2. Duplicate Nodes: Check CodeField is unique
  3. Missing Children: Verify ParentField values match CodeField values
  4. Slow Performance: Use BeginUpdate/EndUpdate or filter large datasets
  5. Master-Detail Not Working: Check MasterSource and MasterFields are configured

Database Exceptions

Handle database errors:

Saving and Loading

While DBTree is data-driven, you can save the tree structure:

Next Steps