Board index » delphi » DB Data-Selection with ComboBox

DB Data-Selection with ComboBox

I want to make a data selection with a ComboBox!
That means:
-the combobox is filled with items from an DB table
-I select an item
-the related items are shown in another table (1->n relation)

I thought this would be a simple task (probably it is!)

I took a DBLookUpComboBox, filled out ListSource and -item. DataSource
left blank. In the OnChange event I set an filter for the related table.
And ... there it is!
BUT when I open the form there is no default-value and I don't know how
I can set this value. A DBLookUpComboBox has no SelectedItem property or
similar. The only idea that I have is to send key-events to the control
(by the way, how can I do this; in VB there is a command like
'SendKey'). This can't be the solution, is there an easier way?

Thanks in advance,
Jan

 

Re:DB Data-Selection with ComboBox


Quote
Jan Weber wrote in message <395263B6.DFB96...@gmx.de>...
>I want to make a data selection with a ComboBox!
>That means:
>-the combobox is filled with items from an DB table
>-I select an item
>-the related items are shown in another table (1->n relation)

>I thought this would be a simple task (probably it is!)

The data-aware combo boxes are not the right solution for this. You
could use a read-only DBGrid to use for selecting, or if there aren't
*too* many records and you really want to use a combobox, then use a
non-dataware combo, iterate the table and fill the combo manually.
When one is picked you can use the combo-entry as a key to query or
locate the records to display in the detail table.

--
Wayne Niddery - WinWright Consulting
RADBooks - http://members.home.net/wniddery/
You have a Right to Free Speech, but not the right to make me listen,
nor to use my property as a soapbox.

Re:DB Data-Selection with ComboBox


One solution is to use a ComboBox instead of a DbComboBox and load the list
by looping through the TTable.

--
Bill Todd (TeamB)
(Questions received via email cannot be answered.)

Re:DB Data-Selection with ComboBox


Sorry Wayne and Bill, but I disagree with both of you.<g>
I think the TDBLookupComboBox is an ideal component for this task.

Jan, if you want to give the combo box a default value, set the KeyValue of
the component in the AfterOpen of the ListSource's dataset. Set it to the
KeyField value of the first row (or which ever row you want to be the
default). You can't do this at design time but it is only one line of code.

Cheers
John Hair
Designer Systems Ltd

Other Threads