This is a migrated thread and some comments may be shown as answers.

MaskedEditBox Change Culture

2 Answers 126 Views
MaskedEditBox
This is a migrated thread and some comments may be shown as answers.
Mehdi
Top achievements
Rank 1
Mehdi asked on 10 Jun 2018, 03:03 PM

Hi Admins

I'm using Last version of the amazing controls Telerik :-)

Have a problem with MaskedEditBox Control.

use this control in Date format. and set the using property to this:

1.txtdatein.MaskType = MaskType.DateTime;
2.txtdatein.Mask = "yyyy/MM/dd";
3.txtdatein.Culture = new CultureInfo("fa-ir");

 

it's ok and work correct. but only in my system that i'm working with VS2017. (Windows 10 pro)

and when test the project another system,(windows 7 & windows 10) the control culture changed to en-us.

meanwhile, in application startup, use the below code for change the thread culture:

1.CultureInfo c = new CultureInfo("fa-Ir");
2. //var info = c.DateTimeFormat;
3.Thread.CurrentThread.CurrentCulture = c;
4.Thread.CurrentThread.CurrentUICulture = c;
5.CultureInfo.DefaultThreadCurrentCulture = c; // Test with and without this line

 

Please Tell me how to fix this problem.

 

2 Answers, 1 is accepted

Sort by
0
Mehdi
Top achievements
Rank 1
answered on 10 Jun 2018, 04:34 PM

hello again

i'm forget to say that:

on startup application (program.cs) culture changed to "fa-ir" and in my own windows that programming with VS, all control culture worked perfect.(my windows 10 location not set to Iran or Set to Persian. is in United State), like radGridView, show date in PERSIAN culture. but on another windows, all control's UIculture change to "en-us". for testing current culture, with button get the culture name. oddball, culture is (Persian) !!!!!

 

 

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 11 Jun 2018, 06:30 AM
Hello, Mehdi,  

It seems to be a specificity of the .NET Framework. The Calendar property of DateTimeFormatInfo accepts only calendars that are valid for the culture associated with this instance of DateTimeFormatInfo. For example, if the current instance originated from the DateTimeFormatInfo property of a "fa-Ir" CultureInfo object, this property can accept only the calendars that are valid for the "fa-Ir" culture. The CultureInfo.Calendar property specifies the default calendar (GregorianCalendar) for the culture and the CultureInfo.OptionalCalendars property specifies all calendars supported by the culture (GregorianCalendar and HijriCalendar).
.NET Framework doesn't support Persian calendar for the culture. This culture doesn't accept the calendar; therefore display of DateTime in this culture is impossible.
A well known solution to solve this problem is declaring a new type like PersianDate. This type wraps DateTime. Developers should use it without functionalities of DateTime and other classes that depend on it. Additional information on this topic is available in the following articles:
https://www.codeproject.com/Articles/32096/How-to-Set-PersianCalendar-to-CultureInfo
https://code.msdn.microsoft.com/Fixing-Persian-Locale-for-6e66e044#content

I hope this information helps. If you have any additional questions, please let me know. 

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
MaskedEditBox
Asked by
Mehdi
Top achievements
Rank 1
Answers by
Mehdi
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or