Setting DateTime Culture in a TextBox cannot be done with CultureInfo

1 Answer 84 Views
Report Designer (standalone)
n/a
Top achievements
Rank 1
n/a asked on 25 Jul 2023, 05:21 PM

Hello guys,

I want to set up a DateTime property from my DB to use the Bulgarian culture inside a TextBox in the Report Designer. It should use one of the following formats "MMMM yyyy" or "Y" (example: декември 2015).

Using the following code I have found that the Culture does not change even though I have specifically set it to Bulgarian in the code, also in the Report culture and TextBox culture:

Fields.ProductionDate.ToString("Y", CultureInfo.GetCurrentCulture("bg-BG"))

What I have found up until now. is that using the following syntax, with the cultures of the Report and TextBox set. including setting the DateTime formatter for the TextBox to be July 2023 fixes the issue:

=Fields.ProductionDate

However, this does not work for me as the TextBox I am using the property in, includes a lot of text and the only way I have found to write code that way is using Curly Braces which do not seem to apply the selected format.

Result when using =Fields.ProductionDate:

Result when using {Fields.ProductionDate}:

Question 1: Is there a way to change the DateTime Format and Culture using the first approach, if so could you please attach a sample as everything so far that I have tried does not seem to work.

Question 2: Is there a way to go around the curly braces and use the =Fields.ProductionDate with square braces without the need to create a separate TextBox.

Thank you in advance.

1 Answer, 1 is accepted

Sort by
1
Momchil
Telerik team
answered on 28 Jul 2023, 12:19 PM

Hi Ivan,

Thank you for the detailed examples.

Let me try to address the issue with the Embedded Expressions syntax first. When this syntax is used, the format applied to the textbox no longer works because the value of the textbox is converted to a string. You can verify this by setting the [= Fields.ProductionDate + ""] expression (without the square brackets) as the textbox's value. Even though we are appending an empty string, the format of the textbox will break.

The good news is that you can take advantage of the Format Text Function and it will use the culture based on the Culture Inheritance. For example, if a textbox has the bg-BG culture set and you use the following expression as a value, the result would be "Test 1: декември 2015 г.".

Test 1: {Format("{{0:Y}}", Fields.ProductionDate)}

Notice that I used double curly brackets in the format argument of the Format Text Function. This is how curly brackets are escaped when using Embedded Expressions.

You could also apply the above using the regular expression syntax if you prefer. For example:

= "Test 1: " + Format("{0:Y}", Fields.ProductionDate)

For reference, I am attaching a sample report that illustrates what I described.

I hope this helps.

Kind Regards,
Momchil
Progress Telerik

Stay tuned by visiting our roadmap and feedback portal pages, enjoy a smooth take-off with our Getting Started resources, or visit the free self-paced technical training at https://learn.telerik.com/.
n/a
Top achievements
Rank 1
commented on 28 Jul 2023, 08:29 PM

Thanks a lot Momchil, this works perfectly!
Tags
Report Designer (standalone)
Asked by
n/a
Top achievements
Rank 1
Answers by
Momchil
Telerik team
Share this question
or