blitzkriegz
blitzkriegz

Reputation: 9576

Add year range [1960 -current year] to combo box

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

Answers (2)

Haris Hasan
Haris Hasan

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

cjk
cjk

Reputation: 46425

Like this?:

for(int i = 1960; i <= DateTime.Now.Year; i++)
{
    combo.Add(i.ToString()) // pseudo
}

Upvotes: 0

Related Questions