17 August 2012

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)); }

No comments: