combobox usage

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi

i have a screen with customer details on it. for some items i only want to
make a combobox available. eg. country - this will hold a defined list of
countries. my question is how i set up the datasource etc. on this combo. of
course, when opening the screen, i want the existing value for this customer
to be shown, eg. UK. but the actual source values of the combo should come
from another table - eg. the countries table.

i'm a little confused on how to set this up, any help appreciated.

rgds,
barry
 
Hi Barry,

More details, please.
What is stored in the "another table"? (Examples)

In the compobox lets say we have:
"UK"
"Norway"'
"Ireland"

What do the "actual source values" look like?

Regards,
Lars-Inge Tønnessen
 
hi lars-inge

thanks for your response. in the main table, i have standard name and
address details, eg. NAME, ADDRESS, POSTCODE, COUNTRY, TELEPHONE. the
COUNTRY field i want to be a dropdown combo. in this table there is a 2
digit code, eg. UK, DE, US, FR etc.

the other table is the lookup table for countries. in here i have the same
2-char country code as above, along with extra info on the country eg.
LONGNAME, SHORTNAME, POPULATION, CONTINENT etc. there is a fixed list of
countries that must be chosen from - ie. no free-text.

in the drop-down i can show either the 2-char code, or the LONGNAME for
example, whichever's easiest. but when the name/address window opens, it
must display the correct value for that particular record.

so, selection of the dropdown is not friving the name&address record that is
selected, it is just altering the particular field value for this record.
hope that helps your understanding of my problem.

many thanks,
barry
 
You can do this in many ways. One of them could be to join the tables in a
SQL Server (if your data source is a database).

An other solution would be to store all the data in the comboBox item. You
can to this by implementing your own ComboListItem that stores the full text
and the short "key".

public class ComboListItem
{
private string _LongName = "";
private string _ShortName = "";

public virtual string LongName
{
get
{
return this._LongName;
}
set
{
this._LongName = value;
}
}

public virtual string ShortName
{
get
{
return this._ShortName;
}
set
{
this._ShortName = value;
}
}

public override string ToString()
{
return this._LongName;
}
}


When you make an object of this class, you would store what the user should
see in the combobox in the LongName-field, and the key in the ShortName
field.

ComboListItem itm = new ComboListItem();
itm.LongName = "England";
itm.ShortName = "UK";
this.comboBox1.Items.Add(itm);

You can now read out the short name from the selected value, or search
through the items in the combobox and show the wanted item.


Regards,
Lars-Inge Tønnessen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top