Reputation: 84792
I have a list of business logic objects that is bound to a Winforms DataGridView
, and it contains DateTime
fields. By default they get converted into a long date and time string.
I want the fields to be converted automatically into HH:MM
format. I've discovered that I can attach a TypeConverterAttribute
to a field with a subclass of TypeConverter
class, but I can't for the life of me figure out how to make DateTimeConverter
accept a custom format string. Is it possible without writing a custom TypeConverter
?
class Foo
{
...
// How to make this converter use a custom format string?
[TypeConverter(typeof(DateTimeConverter))]
public DateTime SomeDateField { get; private set; }
...
}
Upvotes: 0
Views: 794
Reputation: 941237
Not sure why you'd consider a TypeConverter. Select the DGV in your form and click the Tasks glyph on the upper right, Edit Columns. Select the column, then DefaultCellStyle on the upper right. Click the dots. Set Format to "HH:MM".
Upvotes: 2