Fill out drop-down lists over the years

I am working on a WPF project and I have a summer summary that should contain the years from 1950 to this year. Any ideas how to proceed?

+4
source share
4 answers

I would write a cycle that begins in 1950 and ends this year. For each iteration of this loop, simply add an entry to the combo box with the current loop counter as content.

Some pseudo codes:

for (int i = 1950; i <= currentYear; i++) { ComboBoxItem item = new ComboBoxItem(); item.Content = i; myCombobox.Items.Add(item); } 
+5
source

How about something like this, assign it as a DataSource

 Enumerable.Range(1950, DateTime.Today.Year).ToList(); 
+12
source

sort of:

 for(int year = 1950; year<DateTime.UtcNow.Year; ++year) { // Add year as year to the combo box item source... } 
+2
source
  for (int i = 1950; i <= 2050; i++) { Year_combo.Items.Add(i); } 
0
source

Source: https://habr.com/ru/post/1368922/


All Articles