2011-05-16 129 views
1

我想在C#的桌面應用程序中使用國家組合框。從哪裏我可以得到這個?因爲不是寫所有我想要一個組合框包含所有國家的列表。從哪裏可以得到C#中的國家組合框?

請幫忙!

+2

桌面應用程序那你爲什麼要添加asp.net標記 – 2011-05-16 10:48:21

+0

那麼桌面應用程序(winforms,wpf)還是web應用程序(asp.net)? – abatishchev 2011-05-16 10:52:20

回答

3

你可以下載CSV或所有國家的XML和插入到你的數據庫,並從數據庫中獲取,以填補組合框,也可以從XML填充組合框也

http://www.andrewpatton.com/countrylist.html

+0

我不想將它插入到數據庫中,以便在組合框中添加。我正在創建桌面應用程序。使用c sharp – 2011-05-16 10:52:35

+1

+1啓動時從XML填充靜態列表 – abatishchev 2011-05-16 10:53:13

+0

使用XML文件...... – 2011-05-16 10:53:18

9

可以使用全球化命名空間來產生國家名單。

public static List<string> GetCountryList() 
{ 
    List<string> cultureList = new List<string>(); 

    CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.SpecificCultures); 

    foreach (CultureInfo culture in cultures) 
    { 
     RegionInfo region = new RegionInfo(culture.LCID); 

     if (!(cultureList.Contains(region.EnglishName))) 
     { 
      cultureList.Add(region.EnglishName); 
     } 
    } 
    return cultureList; 
} 

記住添加using System.Globalization 如果需要本地名稱,您可以用region.NativeName更換region.EnglishName