2

我目前正在 c#.Net 中的 PropertyGrid 中处理一些 DateTime 属性。我使用默认的下拉日期时间选择器。

我的问题:有没有办法显示完整的日期和时间?默认情况下,如果没有设置时间,则会显示日期,但我也想要零值。即:我希望显示“09.11.2009 00:00”而不是“09.11.2009”。

我必须为此使用一些自定义 TypeConverter 或 Editor 吗?我在这个propertygrid中感到很失落,这让我很难过......

任何帮助,将不胜感激!谢谢 :)

4

1 回答 1

4

Yes, you need your own TypeConverter. Derive it from DateTimeConverter and override the ConvertTo method. If you look this method in Reflector you will see this piece of code inside:

if (time.TimeOfDay.TotalSeconds == 0.0)
    return time.ToString("yyyy-MM-dd", culture);

Just remove that for example.

Nicolas

于 2009-11-09T16:51:06.990 回答