I am working on a WPF project and I have a years combobox that should contain years from 1950 to present year. Any ideas how proceed ?
How about something like this, assign it as DataSource
Enumerable.Range(1950, DateTime.Today.Year).ToList();
I would write a loop that starts at 1950 and ends at the current year. For every iteration of this loop just add an entry to the combobox with the current loop counter as content.
Some pseudocode:
for (int i = 1950; i <= currentYear; i++) {
ComboBoxItem item = new ComboBoxItem();
item.Content = i;
myCombobox.Items.Add(item);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With