TDBLookupListBox & TDBLookupComboBox question

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)?
girlswants_meAsked:
Who is Participating?
 
kretzschmarConnect With a Mentor Commented:
use the afteropen-event of your lookupdataset like
(dataset is in the desired order and not empty)

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

meikl ;-)
0
 
girlswants_meAuthor Commented:
anybody
0
 
girlswants_meAuthor Commented:
I'm using Delphi 7

When the form load automatically the first record in the table is selected (highlighted)
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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

meikl ;-)
0
 
girlswants_meAuthor Commented:
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
0
 
girlswants_meAuthor Commented:
The first time the form load, i want that my DBLookuplistbox2 should have the first record highlighted or selected.
0
 
girlswants_meAuthor Commented:
Meikl ;-) YOUR ARE GENIUS!!!! Thank you very much... I raised the points by 25

please see below for the solution.

 mDBTables_Module.db_ItemEntry.First;
 mDBTables_Module.db_ItemCategory.First;
 DBLookupComboBox1.KeyValue := mDBTables_Module.db_ItemCategory.FieldByName('CODE').Value;
 DBLookupListBox2.KeyValue := mDBTables_Module.db_ItemEntry.FieldByName('LONGDESC').Value;
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.