1

I am creating a combobox that populate the parent and child list.

I have already 2 separate combobox for parent and child. What I want to see is to have these in one combobox having the child list under its parent list. Of course the child is indented for easy viewing

Here's the sample image that I want to achieve.

enter image description here

On the other hand, is there any other combobox component available that do this type of dropdownlisting.

Appreciate any help on this.

UPDATE: Forgot to mention that the data are coming from 2 tables using clientdatasets. Meaning, I have to populate from 2 tables to one combobox using loops between 2 tables.

Mel
  • 101
  • 1
  • 9

1 Answers1

1

Standard ComboBox controls do not support multiple levels like you want. However, that is not hard to accomplish by simply inserting whitespace in front of "child" items, eg:

ComboBox1.Items.Add('Dunning''s Pool Depot, Inc.');
ComboBox1.Items.Add('  Big City Store #002');
ComboBox1.Items.Add('  Littleton Store #445');
ComboBox1.Items.Add('  ...');

ComboBox1.Items.Add('Peacock Home Builders');
ComboBox1.Items.Add('  Baxter Street');
ComboBox1.Items.Add('  Elm Wood Drive');
ComboBox1.Items.Add('  ...');

Given an index of any item, you can determine if it is a "parent" or a "child" by simply looking if it has leading whitespace. Or, you can use the Items.Objects[] property to store per-item context data, such as the type ("parent" or "child"), index of parent, etc.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I forgot to mention that these comobobox are coming from 2 tables using clientdatasets. So, I have to figure out lookping in between 2 tables, right? – Mel Aug 04 '19 at 05:46
  • To "get at" the source CDS, you could use `ComboBox1.Items.AddObject('Dunning''s Pool Depot, Inc.', CDS1)`, etc. – MartynA Aug 04 '19 at 08:53