Completed
Last Updated: 23 Feb 2021 10:36 by ADMIN
Release R1 2021 SP2
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 24 Feb 2014 12:39
Category: PropertyGrid
Type: Bug Report
5
FIX. RadPropertyGrid - PropertyGridSpinEditor automatically rounds decimal values to 2 decimal places no matter the BaseSpinEditorElement.DecimalPlaces property
Workaround:
 Private Sub RadPropertyGrid1_EditorRequired(sender As Object, e As PropertyGridEditorRequiredEventArgs) Handles RadPropertyGrid1.EditorRequired
     Dim te As PropertyGridTableElement = TryCast(sender, PropertyGridTableElement)
     If e.EditorType = GetType(PropertyGridSpinEditor) Then
         Dim editor As New CustomPropertyGridSpinEditor
         If editor IsNot Nothing AndAlso te IsNot Nothing Then
             Dim type As Type = RadPropertyGrid1.SelectedObject.[GetType]().GetProperty(e.Item.Name).PropertyType
             If type = GetType(System.Double) Then
                 DirectCast(editor.EditorElement, BaseSpinEditorElement).DecimalPlaces = 4
                 e.Editor = editor
             End If
         End If
     End If
 End Sub

 Public Class CustomPropertyGridSpinEditor
     Inherits PropertyGridSpinEditor
     Public Overrides Sub Initialize(owner As Object, value As Object)
         Dim decimalPlaces As Integer = Me.DecimalPlaces
         MyBase.Initialize(owner, value)

         Dim element As PropertyGridItemElement = TryCast(owner, PropertyGridItemElement)
         Dim item As PropertyGridItem = TryCast(element.Data, PropertyGridItem)
         Dim editedType As Type = item.PropertyType

        If ((editedType = GetType(Decimal) OrElse editedType = GetType(Double) OrElse editedType = GetType(Single)) AndAlso decimalPlaces <> 0) Then
         DirectCast(Me.EditorElement, BaseSpinEditorElement).DecimalPlaces = decimalPlaces
         Me.Value = value
       End If
     End Sub
 End Class
0 comments