Board index » delphi » TDBComboBox: Selecting Country, Store Country code but show Country code + Country name

TDBComboBox: Selecting Country, Store Country code but show Country code + Country name

Hello,
I'm building an input form for a customers table and want to show a
TDBComboBox with all the countries in the world to let the user select the
correct country.
I have populated the TDBComboBox item list with strings like:

    Add('AD - Andorra');
    Add('AE - United Arab Emirates');
    Add('AF - Afghanistan');
    Add('AG - Antigua and Barbuda');

I have connected the TDBComboBox to a table field of type TEXT with a size
of 2 chars.
If I select a country and then Post the record then the first two chars of
the selected country are
stored in the table field, like I wanted.
But when I scroll in the table the  TDBComboBox shows only an empty field,
probable because he
can't find a matching item.

If I populate the TDBComboBox item list with string like:
    Add('AD');
    Add('AE');
    Add('AF');
    Add('AG');
Then it work, but the user sees only the 2 character code and I will show
him the country name as well.

Is there a way to do this ?

Thanks in advance
and Happy New Year to all

 

Re:TDBComboBox: Selecting Country, Store Country code but show Country code + Country name


Quote
>If I populate the TDBComboBox item list with string like:
>    Add('AD');
>    Add('AE');
>    Add('AF');
>    Add('AG');
>Then it work, but the user sees only the 2 character code and I will show
>him the country name as well.

>Is there a way to do this ?

One way to do this would be to use a TdbLookupCombobox where you would put these
value pairs into a table that you use as the TdbLookupCombobox.listsource.

There are also quite a few 3rd party Dbcombobox components that allow you to Map
values like you are trying to do.  I use the DbCombobox component from InfoPower
www.woll2woll.com

--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Re:TDBComboBox: Selecting Country, Store Country code but show Country code + Country name


"Willy verbiest" <willy.verbi...@pandora.no spam.be> wrote in message
news:3e14cc99$2@newsgroups.borland.com...

Quote
> I have populated the TDBComboBox item list with strings like:

>     Add('AD - Andorra');
>     Add('AE - United Arab Emirates');
>     Add('AF - Afghanistan');
>     Add('AG - Antigua and Barbuda');

> I have connected the TDBComboBox to a table field of type TEXT with a size
> of 2 chars.
> If I select a country and then Post the record then the first two chars of
> the selected country are
> stored in the table field, like I wanted.
> But when I scroll in the table the  TDBComboBox shows only an empty field,
> probable because he
> can't find a matching item.

You can use the OnGetText / OnSetText events of the TField to control this.

--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
"Democracy, without that guarantee of liberty, is merely a method of
selecting tyrants." - Alan Nitikman

Re:TDBComboBox: Selecting Country, Store Country code but show Country code + Country name


Hello Brian,

 Thanks for the hints, it works. I only have difficulties to
 display this in a Label field in a form where the user is not allowed to
change it.

 As a solution I've puted two extra TADOQuery (State & Country) on the
 "Contacts" form and in the onShow event I've entered the following lines:

   with qryCountries do
   begin
     SQL.Clear;
     SQL.Add('SELECT *');
     SQL.Add('FROM tblCountries');
     SQL.Add('WHERE tblCountries.[CountryID] = :Country');
   end;
   qryCountries.Active := true;
   LabelCountry.Caption := qryCountries.FieldByName('Country').AsString;

 The qryCountries uses the Datasource dsCustomers
 This works but I think that there are better way's to do it.

 Kind regards,

 Willy Verbiest
 Belgium

Brian: Sorry for the direct mail answer, it was a mistake on my side.

"Brian Bushay TeamB" <BBus...@Nmpls.com> schreef in bericht
news:2bv91v83kusvan0gu5a76fuv20j23ist6v@4ax.com...

Quote

> >If I populate the TDBComboBox item list with string like:
> >    Add('AD');
> >    Add('AE');
> >    Add('AF');
> >    Add('AG');
> >Then it work, but the user sees only the 2 character code and I will show
> >him the country name as well.

> >Is there a way to do this ?

> One way to do this would be to use a TdbLookupCombobox where you would put
these
> value pairs into a table that you use as the TdbLookupCombobox.listsource.

> There are also quite a few 3rd party Dbcombobox components that allow you
to Map
> values like you are trying to do.  I use the DbCombobox component from
InfoPower
> www.woll2woll.com

> --
> Brian Bushay (TeamB)
> Bbus...@NMPLS.com

Re:TDBComboBox: Selecting Country, Store Country code but show Country code + Country name


Quote
> The qryCountries uses the Datasource dsCustomers
> This works but I think that there are better way's to do it.

I can't follow how any of this applies to your original question.
--
Brian Bushay (TeamB)
Bbus...@NMPLS.com

Other Threads