Is there a way to have a decimal column that does not display the trailing zeros when editing a value?
I tried changing the Editor to an UltraNumericEditor but it keeps including mask characters and a $ that I do not want.
I just simply want the raw decimal number without the trailing zeros.
I see in the past it has been said that it is not possible, without some funky workarounds at which point it would be better to just force the column type to be double. (This will also be a pain for me).
Note that I am using currently Infragistics 2013 Volume 1.
I appreciate any help that is offered.Thank you.
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
Hi,
I have used your DataFilter with the sample I have provided and it seems to me that it works fairly well. The only thing I would change is the ConvertValueEditor method the following way:
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)
Dim returnString = decimalValue.ToString()
If (returnString.Contains(".")) Then
Return returnString.TrimEnd("0"c).TrimEnd("."c)
Else
Return returnString
End If
Return value.ToString
End Function
The previous version can trim a number like 340.0 to just 34, using two consecutive EndTrims ensures that it won’t happen. Other than that everything seems fine for me.
Please let me know if you have any additional questions.
Nice catch, Thank you for all your help.