I tried to apply your suggested modifications in my code, but unfortunately I ran into a few issues.
1. The Column Formatting was being ignored. Trying to manually apply the formatting was problematic for me at best.
2. My project is actually in VB.Net, and as such the precision conversion was not working since it is auto stripping the ZEROS out of the decimal number (a bug I think) Notice I used String manipulation instead (TrimEnd, etc.).
I created this and it seems to do what I want. I tried to use the OnBeforeEnterEditMode, but any attempt I made to set the text box text, was overridden by the system.
If you have any suggestions on how to do this better, I would greatly appreciate it. If everything is pretty much as good as it gets, let me know too please.
Thank You for all of your help with this.
Seradex.
Friend Class CustomDecimalEditorWithText
Inherits EditorWithText
Protected Overrides Sub OnAfterEnterEditMode()
Me.SetTextBoxText(CType(Me.DataFilter, CustomDecimalDataFilter).
ConvertValueToEditor(Me.Value), True)
MyBase.OnAfterEnterEditMode()
End Sub
End Class
Friend Class CustomDecimalDataFilter
Implements IEditorDataFilter
Public Function Convert(ByVal conversionArgs As EditorDataFilterConvertArgs) As
Object Implements IEditorDataFilter.Convert
Dim value As Object
Dim decimalValue As Decimal
Dim ReturnValue As String
Select Case conversionArgs.Direction
Case ConversionDirection.EditorToOwner
value = conversionArgs.Value
If value IsNot Nothing AndAlso TypeOf value Is String AndAlso Decimal.TryParse(
value.ToString(), decimalValue) Then
conversionArgs.Handled = True
conversionArgs.IsValid = True
If decimalValue.ToString.TrimEnd("0"c, "."c).Contains(".") Then
Dim DecimalsLocation As Integer
DecimalsLocation = decimalValue.ToString.IndexOf(".") + 1
ReturnValue = decimalValue.ToString.Substring(0, DecimalsLocation) &
decimalValue.ToString.Substring(DecimalsLocation).PadRight(14, "0"c)
Else
ReturnValue = decimalValue.ToString & ".00000000000000"
End If
Return ReturnValue
End If
End Select
Return conversionArgs.Value
End Function
Public Function ConvertValueToEditor(value As Object) As String
Dim decimalValue As Decimal
If value IsNot Nothing AndAlso TypeOf value Is Decimal Then
decimalValue = DirectCast(value, Decimal)
Return decimalValue.ToString.TrimEnd("0"c, "."c)
End If
Return value.ToString
End Function
End Class