• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 814
  • Last Modified:

Delphi db aware components

Hello

I want a component which will list the values in a database table to a field but I do not need to return the the selected value. I want to display the contents of the table but I do not need to update it do I still use a dbcombobox or do I use a regular combobox perform a query a loop through the results to populate the combobox?

Thanks

Jake
0
elschott
Asked:
elschott
  • 3
2 Solutions
 
rfwoolfCommented:
Hi. You should use a DBLookupComboBox.
To populate the 'list' you will use ListSource - and give it a datasource, Keyfield - and give it an indexed field in that table (I usually just put the field whose list I want to be shown, but best practise is to put any indexed field), and finally set 'List Field' to the field whose list you want to be shown.

You would only need to use a loop through a table to add its results IF that table wasn't uni-directional, i.e. if your table can only show one record/row at a time.
0
 
rfwoolfCommented:
Correction:
You would only need to use a loop through a table to add its results IF that *dataset* *was* uni-directional, such as DBexpress.
There are other cases where I have opted to do a loop-through, but that isn't strictly 'data-aware' and therefore isn't best practise. Where possible, use a DBLookupComboBox and use the ListSource.
0
 
rfwoolfCommented:
Oh, and in the DBLookupCombobox, make sure you set the Datasource and DataField properties blank.
Then once the user has selected you can say
DBLookupComboBox1.text to read the string value of the box.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now