I am beginner in .net. I need to show day, month and year in three different comboboxes. To make them fill i was trying hardcoded values from 1950 to present year. which i later realized that i need to check for also ferbruary(28 days), leap year and other issues. Is there any other way to do this without hardcoding the values.
while searching for answer on internet i came across datepicker and monthcalendar which i dont want to use(because my project should be unique from my other friends who are using datepicker and monthcalendar). or else if you have any other suggestions instead of comboboxes please share.

I am sure someone has asked this question before. I dont mind if you direct the link.
EDITED after nikhil agrawal’s answer:
Working Code:
cmbDay ---> combobox
cmbMonth ---> combobox
cmbYear ---> combobox
FormLoad event
this.cmbYear.Leave+=new EventHandler(cmbYear_Leave);
this.cmbDay.Leave += new EventHandler(cmbYear_Leave);
this.cmbMonth.Leave += new EventHandler(cmbYear_Leave);
//
for (int i = 1950; i < 2012; i++)
{
cmbYear.Items.Add(i.ToString());
}
for (int i = 1; i < 32; i++)
{
cmbDay.Items.Add(i.ToString());
}
//
cmbDay.SelectedIndex = 0;
cmbMonth.SelectedIndex = 0;
cmbYear.SelectedIndex = 0;
OnLeave Event
private void cmbYear_Leave(object sender, EventArgs e)
{
int day = DateTime.DaysInMonth(Convert.ToInt32(cmbYear.Text), cmbMonth.SelectedIndex+1);
if (day <= cmbDay.SelectedIndex)
{
//alert message or your managing code.
}
}
PS: cmbMonth is in string format (“Jan”,”Feb”,”Mar”,…)
Populate all three with all possible values like for date 1 to 31, for month Jan to Dec and year 1950 to present year.
Check for valid date when lost focus on all three using
for year you can directly cast selected item to int and for month you can find selectedindex +1 (coz index is 0 based).
Now on lost focus(one single lost focus event on all three’s lost focus) check if the date is less or equal to days returned by method. If not then alert message or something.