Articles → .NET → Binding Combo Box Using Generic Class
Binding Combo Box Using Generic Class
using System;
public class Country {
public int CountryID {
get;
set;
}
public string CountryName {
get;
set;
}
}
public List < Country > CountryCollection {
get;
set;
}
CountryCollection = new List<Country>();
Country CountryObject = new Country();
CountryObject.CountryID = 1;
CountryObject.CountryName = "India";
CountryCollection.Add(CountryObject);
CountryObject = new Country();
CountryObject.CountryID = 2;
CountryObject.CountryName = "Sri Lanka";
CountryCollection.Add(CountryObject);
CountryObject = new Country();
CountryObject.CountryID = 3;
CountryObject.CountryName = "Australia";
CountryCollection.Add(CountryObject);
comboBox1.DataSource = CountryCollection;