Article View: borland.public.cppbuilder.database.ado
Article #5160Re: Question about the TDBLookupComboBox Control
From: Giuliano
Date: Sun, 29 Jul 2001 08:55
Date: Sun, 29 Jul 2001 08:55
33 lines
2240 bytes
2240 bytes
On Sat, 28 Jul 2001 18:20:59 -0400, "goat" <goat@psu.edu> wrote:
>I am using a TDBLookupComboBox control to select and display records within
>a database. The control works fine for selecting the records, but the only
>thing that I can't figure out is how to fill the edit portion of the
>combobox when the program is intial displayed. (ie. When the program
>starts, the TDBLookupComboBox is initial blank, but when the control is
>clicked the drop-down portion of the control displays the correct data and
>when the user selects and item the list closes and display the correct item
>in the edit portion of the control. ). So how do I intially fill (or select
>an item) the edit portion of the control?
>Thanks in advance....
>Mitch
>
You have to set TDBLookupComboBox::KeyValue when you are opening the
associated dataset, or when the linked TDataSource's OnDataChange event
handler is fired. Try with something like the following code:
void __fastcall TForm1::DataSource1DataChange(TObject *Sender,
TField *Field)
{
const AnsiString KeyField( DBLookupComboBox1->KeyField );
TDataSource& DataSource( *DBLookupComboBox1->ListSource );
TDataSet& DataSet( *DataSource.DataSet );
DBLookupComboBox1->KeyValue = DataSet.FieldByName( KeyField )->Value;
}
Hope this helps.
Ciao!
Giuliano
Technical Details
Message-ID:
<3b67ce7d.341773604@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!peer.news.opaltelecom.net!newsfeed.wirehub.nl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnewsReferences:
<3b6336d4_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,62d882a12fe54bb X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2001-07-29 02:10:56 PST From: gcardinali@remove.adhoc.net (Giuliano) Newsgroups: borland.public.cppbuilder.database.ado Subject: Re: Question about the TDBLookupComboBox Control Date: Sun, 29 Jul 2001 08:55:49 GMT Message-ID: <3b67ce7d.341773604@newsgroups.borland.com> References: <3b6336d4_1@dnews> X-Newsreader: Forte Agent 1.5/32.451 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 194.183.68.131 X-Trace: dnews 996397265 194.183.68.131 (29 Jul 2001 02:01:05 -0700) Lines: 33 Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!peer.news.opaltelecom.net!newsfeed.wirehub.nl!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews