Hi Matthew,
You can subscribe to the
EditorInitialized event and get access to the
PropertyGridDateTimeEditor. You can use the
ItemFormatting event to show only time. Here is an example which result is demonstrated in the attached picture:
public
partial
class
RadForm1 : Telerik.WinControls.UI.RadForm
{
public
RadForm1()
{
InitializeComponent();
this
.radPropertyGrid1.SelectedObject =
new
MyObject() { Time = DateTime.Now, Text =
"Time:"
};
this
.radPropertyGrid1.EditorInitialized += RadPropertyGrid1_EditorInitialized;
this
.radPropertyGrid1.ItemFormatting += RadPropertyGrid1_ItemFormatting;
}
private
void
RadPropertyGrid1_ItemFormatting(
object
sender, PropertyGridItemFormattingEventArgs e)
{
if
(e.Item.Name ==
"Time"
)
{
var value = (DateTime)(e.Item
as
PropertyGridItem).Value;
var element = e.VisualElement
as
PropertyGridItemElement;
if
(element !=
null
)
{
element.ValueElement.Text = value.ToShortTimeString();
}
}
}
private
void
RadPropertyGrid1_EditorInitialized(
object
sender, PropertyGridItemEditorInitializedEventArgs e)
{
if
(e.Item.Name ==
"Time"
)
{
var editor = e.Editor
as
PropertyGridDateTimeEditor;
var element = editor.EditorElement
as
BaseDateTimeEditorElement;
element.Format = DateTimePickerFormat.Custom;
element.CustomFormat =
"hh:mm"
;
element.ShowTimePicker =
true
;
element.Calendar.Visible =
false
;
}
}
}
class
MyObject
{
public
string
Text {
get
;
set
; }
public
DateTime Time {
get
;
set
; }
}
Please refer to the following help articles for more information about customizing the items appearance and customizing the editor behavior in the
RadPropertyGrid:
https://docs.telerik.com/devtools/winforms/controls/propertygrid/customizing-appearance/customization
https://docs.telerik.com/devtools/winforms/controls/propertygrid/editors/customizing-editor-behavior
I hope this information helps. Should you have any other questions, I will be glad to help.
Regards,
Nadya
Progress Telerik
Get
quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers.
Learn More.