.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Use of DataTimePicker MinData and MaxDate Property

Posted By:Narayanan       Posted Date: August 16, 2012    Points: 200    Category: C#    URL: http://www.dotnetspark.com  

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.cs
ListBox: lstFinalcialYear
Button: btncall
DateTimePicker:dtpfinanceDate
ComboBox=CmbCountry

Declaraiotn Part:
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));
        }

 Subscribe to Articles

     

Further Readings:

Responses
Author: netgrid         Company URL: http://www.dotnetspark.com
Posted Date: November 02, 2012

The following code example creates a new instance of a DateTimePicker control and initializes it.
public void CreateMyDateTimePicker()
{
// Create a new DateTimePicker control and initialize it.
DateTimePicker dateTimePicker1 = new DateTimePicker();

// Set the MinDate and MaxDate.
dateTimePicker1.MinDate = new DateTime(1985, 6, 20);
dateTimePicker1.MaxDate = DateTime.Today;

// Set the CustomFormat string.
dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
dateTimePicker1.Format = DateTimePickerFormat.Custom;

// Show the CheckBox and display the control as an up-down control.
dateTimePicker1.ShowCheckBox = true;
dateTimePicker1.ShowUpDown = true;
}more detail you can visit dapfor. com
Author: netgrid         Company URL: http://www.dotnetspark.com
Posted Date: November 02, 2012

The following code example creates a new instance of a DateTimePicker control and initializes it.
public void CreateMyDateTimePicker()
{
// Create a new DateTimePicker control and initialize it.
DateTimePicker dateTimePicker1 = new DateTimePicker();

// Set the MinDate and MaxDate.
dateTimePicker1.MinDate = new DateTime(1985, 6, 20);
dateTimePicker1.MaxDate = DateTime.Today;

// Set the CustomFormat string.
dateTimePicker1.CustomFormat = "MMMM dd, yyyy - dddd";
dateTimePicker1.Format = DateTimePickerFormat.Custom;

// Show the CheckBox and display the control as an up-down control.
dateTimePicker1.ShowCheckBox = true;
dateTimePicker1.ShowUpDown = true;
}more detail you can visit dapfor. com

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend