我正在为(telerik)RadGridView动态创建列,我希望双NaN值显示为空字符串,目前它们显示为' NaN'。
有谁知道怎么做?
我希望有DataFormatString
这个吗?
var column = new GridViewDataColumn
{
Header = ExtractFriendlyName(member),
DataType = valueType,
DataMemberBinding = new Binding(member),
};
通常我会使用FormatInfo
类来执行此操作,例如:
var nfi = (NumberFormatInfo) NumberFormatInfo.CurrentInfo.Clone();
nfi.NaNSymbol = "NaN";
double num = double.NaN;
string numString = System.Number.FormatDouble(num, null, nfi);
答案 0 :(得分:2)
这个简单的绑定转换器可以满足您的需求:
public class DoubleToStringConverter : IValueConverter
{
public object Convert(
object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is double)
{
double number = (double)value;
value = double.IsNaN(number) ? string.Empty : number.ToString(culture);
}
return value;
}
public object ConvertBack(
object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException();
}
}
...
DataMemberBinding = new Binding(member) { Converter = new DoubleToStringConverter() },