Hi,
I need to change the default edit format of a DateTime field in the RadPropertyGrid.
Currently, the mask is presented as "Saturday, September 19, 2020", but I want it to be "19/09/2020" (day / month / year)
Best regards,
4 Answers, 1 is accepted
Hello, Eusebio,
In order to customize the PropertyGridDateTimeEditor, it is suitable to use the EditorInitialized event. Please refer to the following code snippet:
private void RadPropertyGrid1_EditorInitialized(object sender, PropertyGridItemEditorInitializedEventArgs e)
{
if (e.Editor is Telerik.WinControls.UI.PropertyGridDateTimeEditor editor)
{
BaseSpinEditorElement el = editor.EditorElement as BaseSpinEditorElement;
BaseDateTimeEditorElement element = editor.EditorElement as BaseDateTimeEditorElement;
element.Format = DateTimePickerFormat.Custom;
element.CustomFormat = "dd/MM/yyyy";
}
}
More information is available here: https://docs.telerik.com/devtools/winforms/controls/propertygrid/editors/overview
I hope this helps. if you have other questions I would be glad to help.
Regards,
Nadya
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.
1. It's working ok. But I prefer that when entering the day, go to the position of the month. Currently, I have to move to the month and year with the right arrow.
2. When it shows, I see dd/mm/yyyy and hour. I don't desire to see the hour. I attach the image.
3. Can you help me with la distortion to show the calendar? I attach the image.
Thanks again!!
rpgMaquina.PropertyGridElement.PropertyTableElement.ValueColumnWidth = 215
Previously it had assigned: 220.
Hello, Eusebio,
Straight to your questions:
1. The MaskDateTimeProvider is responsible for the parsing of the dates. The MaskDateTimeProvider can be accessed by casting to that appropriate class. This provider contains useful properties and methods that can help you to navigate through the date parts. More information you can find here: https://docs.telerik.com/devtools/winforms/controls/editors/datetimepicker/maskdatetimeprovider
In order to go to the month position when you enter edit mode in the PropertyGridDateTimeEditor, you should create a custom editor and override its BeginEdit method. Please refer to the following example:
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
public RadForm1()
{
InitializeComponent();
this.radPropertyGrid1.SelectedObject = new MyObject() { Date = DateTime.Today, Text = "Date:" };
this.radPropertyGrid1.EditorRequired += this.RadPropertyGrid1_EditorRequired;
}
private void RadPropertyGrid1_EditorRequired(object sender, PropertyGridEditorRequiredEventArgs e)
{
if (e.EditorType == typeof(Telerik.WinControls.UI.PropertyGridDateTimeEditor))
{
e.Editor = new MyPropertyGridDateTimeEditor();
}
}
}
class MyObject
{
public string Text { get; set; }
public DateTime Date { get; set; }
}
public class MyPropertyGridDateTimeEditor : Telerik.WinControls.UI.PropertyGridDateTimeEditor
{
public override void BeginEdit()
{
base.BeginEdit();
BaseDateTimeEditorElement element = this.EditorElement as BaseDateTimeEditorElement;
element.Format = DateTimePickerFormat.Custom;
element.CustomFormat = "dd/MM/yyyy";
MaskDateTimeProvider provider = element.TextBoxElement.Provider as MaskDateTimeProvider;
provider.SelectNextEditableItem();
element.TextBoxElement.TextBoxItem.SelectionStart = 3;
}
}
2. If you apply a custom format as "dd/MM/yyyy" you shouldn't be able to see the time part. Please refer to the following article: https://docs.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings
3. According to the second provided picture it seems that the calendar really looks cut off on your end. Could you please specify if you use any custom theme or have additional customizations? On my end it is shown correctly:
I hope this information helps. Let me know if you need further assistance.
Regards,
Nadya
Progress Telerik
Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive, special prizes, and more, for FREE?! Register now for DevReach 2.0(20).