Jump to content
Dave Novo

combobox with custom drop down (treeview)

Recommended Posts

Hello,

Does anyone have any tips how to make a combo box with a custom drop down editor? For example, I would like to have the dropdown editor be a treeview, and ideally use a virtual string tree as the dropdown editor. Is there a base class in the Delphi hiearchy that is designed for this, or examples of a working one. My google searches have not turned up a nice example.

Edited by Dave Novo

Share this post


Link to post
11 hours ago, Dave Novo said:

Does anyone have any tips how to make a combo box with a custom drop down editor?

The native VCL TComboBox does not support a custom drop down.

11 hours ago, Dave Novo said:

For example, I would like to have the dropdown editor be a treeview, and ideally use a virtual string tree as the dropdown editor.

There is nothing like that for the native VCL TComboBox, so you will have to use a 3rd party solution (for instance, TMS has a TAdvTreeComboBox component, and there is (an older) TreeComboBox available on Torry.net).  Otherwise, you would have to write your own component.

11 hours ago, Dave Novo said:

Is there a base class in the Delphi hiearchy that is designed for this

No.

Share this post


Link to post

I'm pretty sure there are many implementations, one of them is in EhLib. Search for "custom panel + combobox", take a look at main component packs (check awesome Delphi list in my signature). The component shouldn't be too complicated

Edited by Fr0sT.Brutal

Share this post


Link to post

Add dropdown menu and when clicked. Activate a hidden treeview menu. 

For example, I'm using a panel instead of a button because there is no color in the buttons 🙂

Share this post


Link to post

After searching myself for way to populate ComboBoxEx with items from TListView in order to be able to filter data I have made recursive function which iterates through all ListView data. It may be usefull.

 

procedure TForm1.btnPopulateClick(Sender: TObject);
var
  lvl: Integer;
  mNode: TTreeNode;
//--
procedure PlaceTreeItem(nTree: TTreeNode; nLvl: Integer);
var
  nIndent, nImg: Integer;
  NextNode, LastNode: TTreeNode;
begin
  nIndent:=nLvl * 2;
  if nTree.HasChildren then nImg:=0 else nImg:=1;
  ComboBoxEx1.ItemsEx.AddItem(nTree.Text, nImg, nImg, nImg, nIndent, nTree.Data);
  if nTree.HasChildren then
    begin
      Inc(lvl);
      NextNode := nTree.getFirstChild;
      LastNode := nTree.GetLastChild;
      while NextNode <> nil do begin
        PlaceTreeItem(NextNode, lvl);
        if NextNode = LastNode then Dec(lvl);
        NextNode := NextNode.getNextSibling;
      end;
    end;
end;
//--
begin
  ComboBoxEx1.Clear;
  lvl:=0;
  mNode := TreeView1.Items.GetFirstNode;
  while Assigned(mNode) do begin
    PlaceTreeItem(mNode, 0);
    mNode := mNode.getNextSibling;
  end;
end;

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×