Reputation: 9576
I need a combobox where the user can select an year (from 1960 - currentyear). What is the most elegant way to populate the combobox?
Upvotes: 0
Views: 4414
Reputation: 30097
Let's say dates is the list and it would be data source for combo box
dates.AddRange(Enumerable.Range(1960, DateTime.Now.Year - 1960 + 1 ));
Upvotes: 5
Reputation: 46425
Like this?:
for(int i = 1960; i <= DateTime.Now.Year; i++)
{
combo.Add(i.ToString()) // pseudo
}
Upvotes: 0