I use a ValueConverter to convert values displayed in the grid as follows;
<
UserControl
x:Class
=
"UserControl1"
xmlns:rad
=
"clr-namespace:DCRAD"
.
.
.>
<
UserControl.Resources
>
.
.
.
<!-- Value Converters -->
<
rad:NumberToFixedStringConverter
x:Key
=
"NumberToFixedString"
/>
.
.
.
</
UserControl.Resources
>
<
telerik:RadGridView
>
<
telerik:RadGridView.Columns
>
.
.
.
<
telerik:GridViewDataColumn
Header
=
"Distance"
UniqueName
=
"Distance"
Width
=
"auto"
>
<
telerik:GridViewDataColumn.AggregateFunctions
>
<
telerik:SumFunction
ResultFormatString
=
"{} {0:0.00}"
/>
</
telerik:GridViewDataColumn.AggregateFunctions
>
<
telerik:GridViewDataColumn.CellTemplate
>
<
DataTemplate
>
<
TextBlock
Text
=
"{Binding Distance, Converter={StaticResource NumberToFixedString}, ConverterParameter=0.00}"
HorizontalAlignment
=
"Right"
/>
</
DataTemplate
>
</
telerik:GridViewDataColumn.CellTemplate
>
</
telerik:GridViewDataColumn
>
.
.
.
</
telerik:RadGridView.Columns
>
</
telerik:RadGridView
>
And the ValueConverter looks like;
Imports
System
Imports
System.ComponentModel
Imports
System.Windows.Data
<ValueConversion(
GetType
(
Object
),
GetType
(
Object
))>
Public
Class
NumberToFixedStringConverter
Implements
IValueConverter
Public
Function
Convert(value
As
Object
, targetType
As
System.Type, parameter
As
Object
, culture
As
System.Globalization.CultureInfo)
As
Object
Implements
System.Windows.Data.IValueConverter.Convert
Dim
sValue
As
String
=
String
.Empty
Dim
sParam
As
String
=
"0.00"
Try
sValue = value.ToString
If
parameter IsNot
Nothing
Then
sParam = parameter.ToString
If
IsNumeric(sValue)
Then
If
Val(sValue) = 0
Then
'If the parameter starts with "+" then return a formatted string; otherwise return an empty string...
If
sParam.StartsWith(
"+"
)
Then
sValue = sParam.Substring(1)
Else
sValue =
String
.Empty
End
If
Else
If
sParam.StartsWith(
"+"
)
Then
sValue = Format(
CType
(sValue,
Double
), sParam.Substring(1))
'If the value is less than the precision to be displayed...
If
sValue = Format(
CType
(0,
Double
), sParam.Substring(1))
Then
sValue = sParam.Substring(1)
Else
sValue = Format(
CType
(sValue,
Double
), sParam)
'If the value is less than the precision to be displayed...
If
sValue = Format(
CType
(0,
Double
), sParam)
Then
sValue =
String
.Empty
End
If
End
If
End
If
Catch
ex
As
Exception
'Don't action the error and return the empty string...
End
Try
Return
sValue
End
Function
Public
Function
ConvertBack(value
As
Object
, targetType
As
System.Type, parameter
As
Object
, culture
As
System.Globalization.CultureInfo)
As
Object
Implements
System.Windows.Data.IValueConverter.ConvertBack
Dim
sValue
As
String
=
String
.Empty
Dim
oValue
As
Object
= 0
Try
sValue = value.ToString
If
(sValue.Length > 0)
Then
If
sValue.EndsWith(
"%"
)
Then
sValue = sValue.Substring(0, sValue.Length - 1)
If
IsNumeric(sValue)
Then
oValue = Val(sValue)
End
If
End
If
Catch
ex
As
Exception
'Don't do anything - return a zero value...
End
Try
Return
oValue
End
Function
End
Class