Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2004
    Posts
    20

    Unanswered: Delphi adotable > list all values as DBComboBox items?

    how I can get the dbcombobox to list all values from an adotable column..?

    I have set up an adoconnection, adotable and datasource to the dbcombobox and it shows the first record on the combobox by default.

    When I change to another record from the grid, it changes the text to that record on the dbcombobox, but the list of the dbcombobox is empty.. do I have to set the items property to something?

    What I'm trying to do is that users could see all usernames in the dbcombobox from users table, and when user selects an username from the dbcombobox, it would display all info on that user at the dbedit boxes below.

    Please help the newbie

  2. #2
    Join Date
    Jul 2004
    Posts
    20
    Ok, I were thinking it all wrong.. did it like this:

    Created these:

    ADOConnection1
    ADOQuery1
    DataSource1
    ComboBox1 (which value controls the other components)
    and all other components as dbcomponents (dbedit/dbcheckboxes and such)

    Set all of the dbcomponents to use adoquery1

    On the form OnShow event I made this:

    ComboBox1.Clear;
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add('SELECT * FROM tablename');
    ADOQuery1.Open;
    while not ADOQuery1.eof do
    begin
    ComboBox1.items.add(ADOQuery1.FieldValues['column_of_the_item']);
    ADOQuery1.next;
    end;
    ComboBox1.ItemIndex := 0;
    ADOQuery1.First;

    And at the ComboBox OnChange event I made this:

    var CbBox_item: string;
    begin
    CbBox_item := ComboBox1.Text;
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add('SELECT * FROM tablename WHERE column_of_the_item Like "'+CbBox_item+'"');
    ADOQuery1.Open;
    end;

    Works great when I got the hang of it how it could be done.. Is there something bad about the way I did it? It works great, but if there's some better/right way to do this, please tell..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •