Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi i use maskedtextbox for give persian datetime from user. my setting for my maskedtextbox is : mask= 0000/00/00 righttoleft=true

and my code for TypeValidationCompleted on maskedtextbox is :

C#
 private readonly Type dateTimeType = typeof(DateTime);
txtDateS.ValidatingType = dateTimeType;
------------------
private void maskedTextBox1_TypeValidationCompleted(object sender, TypeValidationEventArgs e)
        {
            MaskedTextBox mtb = (MaskedTextBox)sender;


            if (!e.IsValidInput)
            {

                toolTip1.IsBalloon = true;
                toolTip1.Show("date is not true", mtb, -100, -30, 5000);
                mtb.Clear();
            }
            else
            {
                DateTime dt;
                if (!DateTime.TryParse(e.ReturnValue.ToString(), out dt))
                {
                    toolTip1.IsBalloon = true;
                    toolTip1.Show("date is not true ", mtb, -100, -30, 5000);
                    e.Cancel = true;
                    mtb.Clear();
                }
            }
        }


now when i Typing in maskedtextbox 1394/02/28 is very good and work. but when i typing in maskedtextbox 1394/02/29 or 1394/02/30 or 1394/02/31 It does not work and give me datetime is not valid why ? why not work for 29 , 30 , 31 ?

how can i solve this problem?
Posted
Comments
HobbyProggy 20-May-15 5:50am    
Is your Date YYYY/MM/dd ? If that would be the case i can tell you there is no 30th/31st of February :) not even a 29th

1 solution

If you are still not further with your problem check out this CP article it looks like a perfectly fit to your problem -> Persian Calendar(PersianDateTime) in C#[^]
 
Share this answer
 
Comments
NorouziFar 23-May-15 0:07am    
i want to use Persian Calendar(PersianDateTime) in C# but that give me error :

Error 2 The type or namespace name 'MD' could not be found (are you missing a using directive or an assembly reference?
HobbyProggy 1-Jun-15 4:47am    
Did you import it correctly and read all the information on this page? A missing Namespace is not a great problem, check if you have added all the reference you need to your project and reread the page i gave you. The MD Namespace is related to this given calendar, therefore i need to ask if you downloaded the Library or copied the code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900