0
在WinGrid(Infragistics的,如果你必须知道),我得到了含int
个列。该值是几秒钟,您可以从中计算时间。我创建了一个IFormatProvider/ICustomFormatter。在我的网格初始化期间,我设置了Format和FormatInfo参数。的getFormat从来没有得到一个类型的IFormatProvider
然而,当的getFormat被称为我的自定义类型格式,类型参数始终是一个的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();
}
}
它的设置的东西。我尝试了不同的东西,但它似乎没有改变GetFormat接收的类型参数。 – Tipx 2011-03-09 20:47:37
奇怪......你的基础数据源是DataTable吗?如果是这种情况,相应dataTable列的类型是否设置为“int”? – digEmAll 2011-03-09 21:43:09
底层数据源是一个绑定源,绑定源的数据源是数据表。我的column.DataType是一个Int32。 – Tipx 2011-03-09 21:45:57