C# DateTimePicker in PropertyGrid

Property grids are great for quickly giving users an interface for interacting with objects in WPF but customising them is not obvious. Luckily it is possible by extending the UIEditor class to launch custom GUI controls.

In this example I wanted to customise the default DateTime handler of PropertyGrid to include hours, minutes and seconds as unfortunately it only shows the date by default. The following class shows how to extend UIEditor in order to launch a pop-up DateTimePicker when the user selects the item.

Then in order to add that to your property grid, add the following to the DateTime item in the class used by the PropertyGrid –

The key part here is the EditorAttribute.

Update

Here’s a great article explaining custom UITypeEditors in more detail – http://bobpowell.net/TypeEditors.aspx

1 Comment

  1. Can u please share your code here…
    I did the same but nothing is happening. Also putting the break points at the constructor doesn’t hit.

Questions? Comments?

© 2024 Acodemics

Theme by Anders NorénUp ↑