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):Configuration
Result Tree
Advanced: Multiple Dataset Levels
For complex hierarchies with more than two dataset levels, use theLayout 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
Large Datasets
Large Datasets
Filtered Data
Filtered Data
On-Demand Loading
On-Demand Loading
For very large datasets, consider loading nodes on-demand:
Database Wizard
TeeTree includes a Database Wizard dialog for visual configuration:- DataSet selection
- Field mappings
- Master-detail relationships
- Layout options
- Node formatting
Common Patterns
File System Browser
File System Browser
Organization Chart
Organization Chart
Category Product Tree
Category Product Tree
Troubleshooting
Database Exceptions
Handle database errors:Saving and Loading
While DBTree is data-driven, you can save the tree structure:Next Steps
- Customize node appearance with Node Formatting
- Add visual relationships with Connections
- Explore Tree Events for interactive features
- Learn about Advanced Layouts for automatic positioning
