В WinGrid (Infragistics, если вы должны знать) я получил столбец, содержащий int
s. Значение - это количество секунд, из которого вы можете рассчитать время. Я создал IFormatProvider / ICustomFormatter, который делает именно это. Во время инициализации сетки я установил параметры Format и FormatInfo.
Однако, когда GetFormat вызывается в моем пользовательском модуле форматирования типов, параметром type всегда является NumberFormatInfo, а не ICustomFormatter. Почему?
Вот мой класс, на случай, если он поможет:
public class SecToTime : IFormatProvider, ICustomFormatter
{
public object GetFormat(Type formatType)
{
if (formatType == typeof(ICustomFormatter))
{
return this;
}
else
{
return null;
}
}
public string Format(string format, object arg, IFormatProvider provider)
{
if (arg is int)
{
int seconds = (int)arg;
int hours = (int)Math.Truncate((double)seconds / 3600);
int minutes = (int)Math.Truncate((double)(seconds / 60) % 60);
seconds = seconds % 60;
return string.Format("{0:hh:mm:ss}", new DateTime(0, 0, 0, hours, minutes, seconds));
}
else
throw new ArgumentNullException();
}
}