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