BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

IndexName and TDBLookupComboBox

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Desktop)
View previous topic :: View next topic  
Author Message
Patrick Beauchamp
Guest





PostPosted: Mon Oct 20, 2003 7:30 am    Post subject: IndexName and TDBLookupComboBox Reply with quote



I have a Categories table that contains the following:

Cat Desc
01 Vegetables
02 Fruits
03 Dairy
....

On my form, I have a TDBLookupComboBox control that I want to use to
list the categories. In my main table, I have a field Cat that refers to the
category is the Categories table.

When I run my application, and I drop down the categories, they are sorted
in Cat order, which is normal. How do I sort them by Desc, which would make
more sense to the end user when the ListField is set to Desc? I tried
changin the index to Desc, however, the TDBLookupComboBox does not work
because there is not match for the Cat field from the main table anymore.


Back to top
Dell Stinnett
Guest





PostPosted: Mon Oct 20, 2003 4:50 pm    Post subject: Re: IndexName and TDBLookupComboBox Reply with quote



The only way I know if to do this is to use something other than a
TDBLookupComboBox. I've used a TComboBox, loaded the descriptions into the
Items stringlist and used the Object property of the stringlist item to
store the "value." You update the actual field value in either the OnExit
event of the TComboBox or the OnBeforePost event of the table. Loading the
categories would look something like this in code:

tblCategory.Open; //use the index to order by description

while not tblCategory.EOF do

cbCategories.Items.AddObject(tblCategory.fieldbyname('Desc').AsString,
TObject(tblCategory.fieldbyname('Cat').AsString);



Setting the value of the field will look something like this:

tblMyTable.FieldByName('Cat').AsString :=
String(cbCategories.Items.Objects[cbCategories.ItemIndex]);

I don't guarantee that this code is exactly correct (I haven't done this
type of thing in quite awhile), but it should be enough to get you started.

-Dell


Back to top
Patrick Beauchamp
Guest





PostPosted: Mon Oct 20, 2003 6:20 pm    Post subject: Re: IndexName and TDBLookupComboBox Reply with quote



I was hoping there was a way to use a data-aware control, but hey, you're
idea is cool. It is actually more than I expected. Thanks a lot!

"Dell Stinnett" <my.name (AT) zcsterling (DOT) com> wrote

Quote:
The only way I know if to do this is to use something other than a
TDBLookupComboBox. I've used a TComboBox, loaded the descriptions into
the
Items stringlist and used the Object property of the stringlist item to
store the "value." You update the actual field value in either the OnExit
event of the TComboBox or the OnBeforePost event of the table. Loading
the
categories would look something like this in code:

tblCategory.Open; //use the index to order by description

while not tblCategory.EOF do

cbCategories.Items.AddObject(tblCategory.fieldbyname('Desc').AsString,
TObject(tblCategory.fieldbyname('Cat').AsString);



Setting the value of the field will look something like this:

tblMyTable.FieldByName('Cat').AsString :=
String(cbCategories.Items.Objects[cbCategories.ItemIndex]);

I don't guarantee that this code is exactly correct (I haven't done this
type of thing in quite awhile), but it should be enough to get you
started.

-Dell





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (Desktop) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.