Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the Proper Item in a Delphi DBLookupComboBox to be Selected

I have a DBLookupComboBox that is wired to a database query. That part is working fine. When I run the program the DBLookupComboBox is populated with the results of the query. I'd like to to see the DBLookupComboBox populated with the first item "Please Select" when the program first runs or when a new item action is initiated. (See below image)

enter image description here

Also, if I'm loading a previously saved database record that had selected Index 2 "Quick Elimination" how would I get the DBLookupComboBox to display that selected entry?

Yes, "Please Select" is index 0 and it is retreived as part of the query.

like image 339
Michael Riley - AKA Gunny Avatar asked Aug 27 '11 02:08

Michael Riley - AKA Gunny


People also ask

What is dblookupcombobox in Delphi?

Databases - Delphi - DBLookupComboBox The DBLookupComboBox provides a simple way to associate a long descriptive name (stored in a lookup table) with a short (or numeric) key. When used with the KADao components, DBLookupComboBox's work fine - they display all related records.

How do I add a dblookupcombobox to a form?

Select the "Data controls" page on the Component Palette and pick a DBLookupComboBox. Drop one anywhere on the form and leave the default name of "DBLookupComboBox1."

How do I show a dblookupcombobox inside a dbgrid cell?

To show a DBLookupComboBox inside a cell of a DBGrid, you first need to make one available at run time... Select the "Data controls" page on the Component Palette and pick a DBLookupComboBox. Drop one anywhere on the form and leave the default name of "DBLookupComboBox1."

When to use dblookupcombobox instead of DBEdit?

As stated above, when your data entry form is made of more data controls DBEdit, DBComboBox, etc. it makes sense to just use DBLookupComboBox without creating.


1 Answers

You could try this (I know you've probably solved it by now, as you asked over 2 years ago), but in case anyone else was interested...

dbluLookup.KeyValue := dbluLookup.ListSource.DataSet.FieldByName(dbluLookup.KeyField).Value;

That simply sets KeyValue to the first record in the ListSource dataset, which should be the row 'Please Select'.

like image 56
Steve Childs Avatar answered Nov 15 '22 00:11

Steve Childs