TDBLookupListBox & TDBLookupComboBox question

Posted on 2005-05-14
Last Modified: 2010-04-05
How to make a record active and currently selected for DBLookupComboBox and DBLookupListBox?

DBLookupComboBox1.ListSource := mDBTables_Module.ds_ItemCategory;
DBLookupComboBox1.KeyField   := 'CODE';
DBLookupComboBox1.ListField  := 'SHRTDESC';

DBLookupListBox2.ListSource := mDBTables_Module.ds_ItemEntry;
DBLookupListBox2.KeyField   := 'LONGDESC';
DBLookupListBox2.ListField  := 'LONGDESC';

Both do not have any datasource and datafield (because i use both for item selection only)

My problem now is how to make the first record selected (highlited with blue)?
Question by:girlswants_me

    Author Comment


    Author Comment

    I'm using Delphi 7

    When the form load automatically the first record in the table is selected (highlighted)
    LVL 27

    Expert Comment

    not sure what you mean,
    but try to set the property keyvalue to the value you need

    meikl ;-)

    Author Comment

    where can i find the keyvalue???
    When the form load automatically the first record in the table is selected (highlighted) <---this is for the DBLookupListBox2

    Author Comment

    The first time the form load, i want that my DBLookuplistbox2 should have the first record highlighted or selected.
    LVL 27

    Accepted Solution

    use the afteropen-event of your lookupdataset like
    (dataset is in the desired order and not empty)

    procedure TForm1.ADOTable1AfterOpen(DataSet: TDataSet);
      DBLookupComboBox1.KeyValue := DataSet.FieldByName(DBLookupComboBox1.KeyField).Value;

    meikl ;-)

    Author Comment

    Meikl ;-) YOUR ARE GENIUS!!!! Thank you very much... I raised the points by 25

    please see below for the solution.

     DBLookupComboBox1.KeyValue := mDBTables_Module.db_ItemCategory.FieldByName('CODE').Value;
     DBLookupListBox2.KeyValue := mDBTables_Module.db_ItemEntry.FieldByName('LONGDESC').Value;

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
    In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now