🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #3438

Re: DBLookupComboBox

#3438
From: Giuliano
Date: Thu, 22 Aug 2002 15:39
33 lines
2260 bytes
On 22 Aug 2002 01:40:45 -0700, "Gareth" <gbh_2@hotmail.com> wrote:

>
>I am fairly new to c++ programming so this maybe an easily solved problem.  
>The thing is i have my DBLookupComboBox linked to a database and if i 
>click on the down arrow it does display al of the items in the table but 
>when i first load the program the field is blank but i want it to automatically 
>display the first record in the table.  This problem also arises when i delete 
>the currently selected record because it leaves the old value in the 
>combo box even though the item is deleted, so i then have to manually 
>select a different item in it.  This is very sloppy the way it is and require 
>help to fix it.

Hi Gareth,

    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: <rb1amusu1o8ksg5metsrm1eq48e7iumfjp@4ax.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-04!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <3d64a38d$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10698b,dc30445dfa374223
X-Google-Attributes: gid10698b,public
X-Google-ArrivalTime: 2002-08-22 08:57:47 PST
From: Giuliano <gcardinali@remove.adhoc.net>
Newsgroups: borland.public.cppbuilder.database.ado
Subject: Re: DBLookupComboBox
Date: Thu, 22 Aug 2002 17:39:42 +0200
Message-ID: <rb1amusu1o8ksg5metsrm1eq48e7iumfjp@4ax.com>
References: <3d64a38d$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.91/32.564
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 194.183.77.198
X-Trace: newsgroups.borland.com 1030030780 194.183.77.198 (22 Aug 2002 08:39:40 -0700)
Lines: 34
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-04!supernews.com!newshosting.com!news-xfer1.atl.newshosting.com!nntp-relay.ihug.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail