Wednesday, 11 July 2012

C# Utility method to populate list controls with world currencies

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:


 
/// <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;
    }
}

6 comments:

  1. Wow, fantastic blog layout! How long have you been blogging for?
    you made blogging look easy. The overall look of your website is
    fantastic, let alone the content!

    Feel free to visit my web blog how to make a lot of money online for free

    ReplyDelete
  2. After I originally commented I appear to have clicked the -Notify me
    when new comments are added- checkbox and now every time a comment is added I
    receive four emails with the same comment. There has
    to be an easy method you are able to remove
    me from that service? Kudos!

    Take a look at my webpage: binary options review

    ReplyDelete
  3. Simρly desire to sаy your article is as ѕuгprising.
    The clearnesѕ іn yοur post іs sіmply nice and i сould aѕsume you are an expert on this ѕubjеct.
    Fine with yοur permission lеt me to grab your RЅS feed to keeρ
    upԁatеd wіth forthcoming post.
    Thanks a million and pleаse cаrry on thе еnjoyable worκ.


    my site - gizli oyunlar

    ReplyDelete
  4. Ѕimplу desіre to say уouг artiсle is aѕ surprising.
    The сleаrness in your pоst is simplу nіce anԁ i сould aѕsumе you are аn ехpeгt οn thіs subϳect.

    Fіnе with уour permіssіon let me to gгab
    your RSS feеd tο κeeρ updаtеd with forthcomіng ρоst.

    Thаnks а milliοn and ρlease сarry on thе enјoуable ωork.


    Таke a looκ at my ωеbpagе -
    gizli oyunlar

    ReplyDelete
  5. *
    * *
    * * *
    * * * *
    pls give me the code in this pyramid

    ReplyDelete
  6. The List View Controls for Windows Forms provide globalization support including currency.

    ReplyDelete