Records in TDBComboBox

I want see all records of one field using TDBComboBox.
How can I do that?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hi There,

If I have understood your question right then I am giving u a working e.g. In the e.g I have a TDBcomboBox which is linked to a particular Datasource. There is another datasource fropped to access all the records from the desired table. I have defined one query to access the desired field from the desired table. On the dropdown event of the the Combobox I am adding each value to the ComboBox. U can do even on formshow or some other suitable place. The only thing u will have to check is that It should execute the code only once in the form. Right now it will execute everytime u dropdown. By setting a flag u can easily achieve it. I hope u find the solution useful.


unit Unit1;


  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls, DBCtrls, DB, DBTables;

  TForm1 = class(TForm)
    DataSource1: TDataSource;
    Query1: TQuery;
    DBComboBox1: TDBComboBox;
    DataSource2: TDataSource;
    Query2: TQuery;
    procedure DBComboBox1DropDown(Sender: TObject);
    { Private declarations }
    { Public declarations }

  Form1: TForm1;


{$R *.DFM}

procedure TForm1.DBComboBox1DropDown(Sender: TObject);
   while not(Query1.Eof) do


Hi sergio_2001,
Yo Bijoyn!

If you don't have enough information with Bijoyn's example, then you can read this :

Filling dblistboxs and dbcomboboxs

Most of Delphi's data aware components will  populate
themselves after they are wired up to a open dataset.  However
DbListboxs and DbComboboxs do not display this characteristic.  
These two components are not for displaying your datasets, but
filling them.  Use of these components is straight forward.  
When you update your table, the value of the DbListbox or
DbCombobox will be posted in the appropriate field.

Filling the DbCombobox or DbListbox the same as filling normal
comboboxs or listboxes.  The lines of text in a listbox or
combobox are really a tstring list.  The "Items" property of
the given component holds this list.  Use the "Add" method for
adding items to a tstring. If you want to use data  types other
than strings they must be converted at run time. If your list
has a blank line at the end, consider setting the
"IntegralHeight" property to True.

Filling a DbListbox with 4 lines programmatically might look
similar to this:

     DbListbox1.items.add('line one');
     DbListbox1.items.add('line two');
     DbListbox1.items.add('line three');
     DbListbox1.items.add('line four');

Filling a DbListbox at design time requires using the object
inspector.  By double clicking on the components "Items"
property, you can bring up the "String List Editor" and input
the desired rows.

Unfortunately, if a combobox is filled this way, there is not
default value.  Setting a DbComboboxs "text" property will
achieve this result.  (the "text" property is not available in
the object inspector, so it must be set programmatically).  
Setting the default value to the first value in the
DbCombobox's list looks like this:        

DbCombobox1.text := DbCombobox1.items[0];

Often it is useful to fill a DBListBox from a dataset.  This
can be done using loop:

procedure TForm1.FormCreate(Sender: TObject);
  with table2 do begin
    while not EOF do

Have a nice day,
Regards Zif.
sergio_2001Author Commented:
Hi all,

I'll evaluate both answers.

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

sergio_2001Author Commented:
Hi all,

All the answers solve. But there are two problems:
- When I open the dbcombobox there are um blank space in the first item(0).
- I can't select one other item than the current item.

Points increased.


The state of the underlying datafield  is not readonly?
Hi Sergio, Yo Zifnab,

If the first record in the combobox is showing blanks then please check if the records in the source table is correct. As for the selection the dataset to which your ComboBox points to, must be edtiable ( ReadOnly = False as Zif as put in the above comment ).

sergio_2001Author Commented:
Hi bijoyn , Zifnab,

- The dataset of records looks good...
- I have the readonly property set to false...

but doesn't works...

Please send your comments...

Hi Sergio,

I think I know what the problem is. Firstly go to the object inspector for your DBComboBox, Click on the items property, U might find a blank line in it. If its there then thats what results in the first blank record in the comboBox. Secondly check the dataset associated with your DbCombobox. It might have its RequestLive property set to false, make it true. If u do both of these things then ur problem will be solved.


sergio_2001Author Commented:
Hi all,


- You are right... I deleted the first item from items property in the object inspector and it works fine....

- About the dbcombobox.... I'm using um ttable dataset... so I don't have the RequestLive property.... I'm using ReadOnly := false... but I can't select and change the record yet...

- But it's good at this moment... send-me the answer....

The question is anwsered.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.