I am working on a Job File System (JFS) for a client and they had the requirement to include a drop down list of currencies on their Purchase Order and Invoice documents, at first I was going to manually put together a list control but on reflection I thought their must be a better way of doing this that is more reusable. So here I have a utility method I put together to populate a ListControl with currency options. I would be interested in any feedback on this and alternative/better methods of achieving the end result:
[code language="csharp"]
/// <summary>
/// Fills the ListControl with ISO currency symbols.
/// </summary>
/// <param name="ctrl">The ListControl.</param>
public static void FillWithISOCurrencySymbols(ListControl ctrl)
{
foreach (CultureInfo cultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
{
RegionInfo regionInfo = new RegionInfo(cultureInfo.LCID);
if (ctrl.Items.FindByValue(regionInfo.ISOCurrencySymbol) == null)
{
ctrl.Items.Add(new ListItem(regionInfo.CurrencyEnglishName, regionInfo.ISOCurrencySymbol));
}
}
RegionInfo currentRegionInfo = new RegionInfo(CultureInfo.CurrentCulture.LCID);
//- Default the selection to the current cultures currency symbol
if (ctrl.Items.FindByValue(currentRegionInfo.ISOCurrencySymbol) != null)
{
ctrl.Items.FindByValue(currentRegionInfo.ISOCurrencySymbol).Selected = true;
}
}
[/code]