TAdvTreeComboBox is a specialized Delphi component from the TMS VCL UI Pack that embeds a true, hierarchical hierarchical TTreeView inside a standard combo box dropdown.
Because the dropdown relies on the standard native VCL TTreeView, configuring it requires a mix of standard tree-node manipulation and specific combo box settings. 🛠️ Step 1: Component Placement & UI Setup Open your project in RAD Studio / Delphi.
Locate TAdvTreeComboBox in your Tool Palette (typically under the “TMS Editors” or “TMS VCL” tab) and drop it onto your form.
(Optional) Add a TImageList to your form if you want to include icons next to the items in your tree dropdown.
Bind the image list by selecting the TAdvTreeComboBox component and assigning your image list to its Images property via the Object Inspector. 🌲 Step 2: Populating the Hierarchy
Because the internal tree layout isn’t a flat list, you must populate it programmatically (typically inside your form’s OnCreate event) by adding parent and child nodes:
procedure TForm1.FormCreate(Sender: TObject); var ParentNode, ChildNode, SubChildNode: TTreeNode; TreeView: TTreeView; begin // Gain direct access to the internal TTreeView control TreeView := AdvTreeComboBox1.TreeView; TreeView.Items.BeginUpdate; try TreeView.Items.Clear; // Add a root level item ParentNode := TreeView.Items.Add(nil, ‘North America’); ParentNode.ImageIndex := 0; // Requires TImageList linked // Add child items underneath the root item ChildNode := TreeView.Items.AddChild(ParentNode, ‘United States’); TreeView.Items.AddChild(ChildNode, ‘Washington’); TreeView.Items.AddChild(ChildNode, ‘California’); ChildNode := TreeView.Items.AddChild(ParentNode, ‘Canada’); TreeView.Items.AddChild(ChildNode, ‘Ontario’); // Add a second root category ParentNode := TreeView.Items.Add(nil, ‘Europe’); TreeView.Items.AddChild(ParentNode, ‘United Kingdom’); TreeView.Items.AddChild(ParentNode, ‘Germany’); finally TreeView.Items.EndUpdate; end; end; Use code with caution.
⚙️ Step 3: Behavior and Selection Behavior Configuration
You need to tell the combo box how to respond when a user interacts with nodes. Select the component and configure these key properties in the Object Inspector:
SelectMode: Determines what action commits a selection and closes the dropdown list.
smClick: Closes the dropdown and selects the item instantly upon a single click.
smDblClick: Requires a double-click to select, allowing users to single-click to expand or collapse branches without closing the list.
DropHeight: Change the height of the dropdown canvas window to prevent clipping long vertical tree branches.
AutoLookup: Set to True if you want the component to jump to and highlight matching tree items dynamically as the user types text into the edit field. 📥 Step 4: Reading the Selected Item
To track what node the user ultimately selected, use the component’s OnChange event or read the node value on demand.
procedure TForm1.AdvTreeComboBox1Change(Sender: TObject); var SelectedNode: TTreeNode; begin // Access the selected node directly from the embedded TreeView SelectedNode := AdvTreeComboBox1.TreeView.Selected; if Assigned(SelectedNode) then begin // Output the text label ShowMessage(‘You selected: ’ + SelectedNode.Text); // Check if it is a parent or a leaf node if SelectedNode.HasChildren then ShowMessage(‘This is a category node.’) else ShowMessage(‘This is a final sub-item.’); end; end; Use code with caution. 🎨 Step 5: Advanced Visual Adjustments
Customizing the Arrow Button: If your users struggle to notice the dropdown trigger, you can swap out the default drop arrow for a custom bitmap by assigning an image to AdvTreeComboBox1.Button.Glyph.
Initial Expansion: If you want all tree categories pre-expanded when the dropdown opens for the first time, call AdvTreeComboBox1.TreeView.FullExpand; right after populating the items in your initialization step. If you would like, please let me know:
Will your tree entries need checkboxes next to each element?
Are you loading your tree data dynamically from a database table?
Do you need to prevent users from selecting category parent nodes? AdvTreeComboBox – TMS VCL UI Pack – TMS Support Center
Leave a Reply