Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update Combobox (display & value)

Status
Not open for further replies.

russland

Programmer
Jan 9, 2003
315
CH
Hi,

I try to load a combobox with an ArrayList of object CultureInfo. For some reason I cannot map them although the ArrayList looks well populated in debugmode.

Any idea or way to appreach it better/quicker? Important, I do need the Name AND NativeName attribute of CultureInfo in the combobox in order to save the Name (LanguageCode) back to the settings file.

Thanks heaps


String[] cultreCode = Properties.Settings.Default.CultureCodes;
//create array of CultreInfo
CultureInfo[] ci = new CultureInfo[cultreCode.Length];
ArrayList alCultreInfo = null;
for(int i=0; i<cultreCode.Length; i++){
try{ alCultreInfo.Add(new CultureInfo(cultreCode));
}
catch (Exception ex){
Console.Out.WriteLine("Exception: {0} ", ex);
//do not handle invalid locales. later: log, this error, report back to the system administration
}
}
comboBoxLanguage.DataSource = alCultreInfo;
comboBoxLanguage.DisplayMember = "NativeName";
comboBoxLanguage.ValueMember = "Name";
comboBoxLanguage.Update();
 
Now, i even tried it with a struct. That didn't impress the compiler neither. Somebody got a hint on how to bind that CultureInfo to the DisplayMember and ValueMember? I'm out of ideas. Every hint is highly appreciated.


private void FormLanguageAndLocale_Load(object sender, EventArgs e)
{
//retrieve culter codes from the settings file
String[] cultreCode = Properties.Settings.Default.CultureCodes;
//create array of CultreInfo
CultureInfo[] ci = new CultureInfo[cultreCode.Length];

//array of cultures
ArrayList Cultures = null;
CultureInfo tmpCult;
for(int i=0; i<cultreCode.Length; i++){
tmpCult = new CultureInfo(cultreCode);
Cultures.Add(new Cultre(tmpCult.Name, tmpCult.NativeName));

}
comboBoxLanguage.DataSource = Cultures;
comboBoxLanguage.DisplayMember = "NativeName";
comboBoxLanguage.ValueMember = "Name";

}


public struct Cultre {
private string name, nativeName;
public Cultre(string name , string nativeName) {
this.name = name;
this.nativeName = nativeName;
}
public string Name { get { return name; } }
public string NativeName { get { return nativeName; } }
}
 


This works fine. We need to INITILIZE the ArrayList (which is a collection). So, it's fairly works easy to bind properties of objects in an arrayList to a combobox. I hope someone profits from this.

private void FormLanguageAndLocale_Load(object sender, EventArgs e)
{
//retrieve culter codes from the settings file
String[] cultreCode = Properties.Settings.Default.CultureCodes;
//create array of CultreInfo
CultureInfo[] ci = new CultureInfo[cultreCode.Length];

//array of cultures
ArrayList alCultreInfo = new ArrayList();
for(int i=0; i<cultreCode.Length; i++){
try{
alCultreInfo.Add(new CultureInfo(cultreCode));
}
catch (Exception ex){
Console.Out.WriteLine("Exception: {0} ", ex);
//do not handle invalid locales. later: log, this error, report back to the system administration
}
}
comboBoxLanguage.DataSource = alCultreInfo;
comboBoxLanguage.DisplayMember = "NativeName";
comboBoxLanguage.ValueMember = "Name";
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top