I’m converting some application code to use NodaTime classes instead of System.DateTime. Part of my application uses the PropertyGrid control to allow a user to edit a class containing both a LocalDate and an Instant. Without changing anything, the PropertyGrid displays the properties okay, but they are no longer editable. What’s the best way of allowing the user to edit these fields.
For the sake of exposition, we can use this class as a representative of the type of thing I’d like to display and edit:
public class User
{
public string Name { get; set; }
public LocalDate BirthDate { get; set; }
public Instant NextAppointment { get; set; }
}
Best I’ve come up with so far:
Step 1: Create TypeConverter’s so that the Noda classes are editable
Step 2: Register TypeConverters
Put this code at the top of your app:
Step 3: Use custom collection editor to handle things like List
This can be registered by adding this attribute to any appropriate properties: