h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Use of DataTimePicker MinData and MaxDate Property

In this Project, I am giving code for using MinDate and MaxDate for One DateTimepicker Control.The main purpose of this project is selecting a Financial year based on Country. In my Project , 1 Forms ,One ListBox,One Button,One ComboBox and One DateTimePicker. Form Name: frmFinancialYear.csListBox: lstFinalcialYear Button: btncallDateTimePicker:dtpfinanceDateComboBox:CmbCountry
public static string selectedValue; public static string countryname;
enum CountryName { India, America }
private void frmFinancialYear_Load(object sender, EventArgs e) { CmbCountry.Items.Add(CountryName.India.ToString()); CmbCountry.Items.Add(CountryName.America.ToString()); }
private static string[] Splitvalues(string str) { result= str.Split('-'); return result; }
private void countrywisedatevalue(string str,string[] selectedyear) { switch (str) { case "India": startingYear = "04/01/" + selectedyear[0]; endingYear = "03/31/" + selectedyear[1]; dtpfinanceDate.MinDate = Convert.ToDateTime(startingYear); dtpfinanceDate.MaxDate = Convert.ToDateTime(endingYear); dtpfinanceDate.Value = dtpfinanceDate.MinDate; break; case "America": startingYear = "01/01/" + selectedyear[0]; endingYear = "12/31/" + selectedyear[0]; dtpfinanceDate.MinDate = Convert.ToDateTime(startingYear); dtpfinanceDate.MaxDate = Convert.ToDateTime(endingYear); dtpfinanceDate.Value = dtpfinanceDate.MinDate; break; } }
private void btncall_Click(object sender, EventArgs e) { selectedValue = lstFinalcialYear.SelectedItem.ToString(); countryname =CmbCountry.Text; countrywisedatevalue(countryname, Splitvalues(selectedValue)); }