Completed
Last Updated: 07 Dec 2016 14:03 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 02 Nov 2016 15:24
Category: Editors
Type: Bug Report
2
FIX. RadMaskedEditBox - user is not allowed to enter numeric value if the initial value is null is simple data binding is used
To reproduce: add a RadMaskedEditBox and use the following code:

Sub New()

    InitializeComponent()

    Me.RadMaskedEditBox1.MaskType = Telerik.WinControls.UI.MaskType.Numeric
    Me.RadMaskedEditBox1.Mask = "N1"
        Dim item As Item = New Item(Nothing, "Item1")
    RadMaskedEditBox1.DataBindings.Add("Value", item, "StockTypeId", True, DataSourceUpdateMode.OnPropertyChanged)
End Sub

Public Class Item
    Private _stockId As Nullable(Of Integer)

    Public Sub New(value As Nullable(Of Integer), name As String)
        Me._stockId = value
    End Sub

    Public Property StockTypeId() As Nullable(Of Integer)
        Get
            Return _stockId
        End Get
        Set(ByVal value As Nullable(Of Integer))
            _stockId = value
            Console.WriteLine(value)
        End Set
    End Property
End Class

The user is not allowed to enter a new numeric value.

Wokraround:

Public Class CustomNumericCharacterTextBoxProvider
    Inherits NumericCharacterTextBoxProvider

    Private owner As RadMaskedEditBoxElement
    Public Sub New(mask As String, culture As CultureInfo, numericType As NumericCharacterTextBoxProvider.RadNumericMaskFormatType, _
    owner As RadMaskedEditBoxElement)
        MyBase.New(mask, culture, numericType, owner)
        Me.owner = owner
    End Sub
    Protected Overrides Function AllowAppendCharacters() As Boolean
        If owner.Text = "" AndAlso owner.Mask = "N1" Then
            Return True
        End If

        Return MyBase.AllowAppendCharacters()
    End Function
End Class

Public Class CustomMaskedEditBox
    Inherits RadMaskedEditBox

    Public Overrides Property ThemeClassName As String
        Get
            Return GetType(RadMaskedEditBox).FullName
        End Get
        Set(value As String)
            MyBase.ThemeClassName = value
        End Set
    End Property

    Public Sub New()
        MyBase.New()
        Me.MaskType = Telerik.WinControls.UI.MaskType.Numeric
        Me.Mask = "N1"
        Dim numericMaskProvider As NumericMaskTextBoxProvider = Me.MaskedEditBoxElement.Provider
        Dim fi As FieldInfo = GetType(NumericMaskTextBoxProvider).GetField("provider", BindingFlags.Instance Or BindingFlags.NonPublic)
        fi.SetValue(numericMaskProvider, _
                    New CustomNumericCharacterTextBoxProvider(numericMaskProvider.Mask, numericMaskProvider.Culture, _
                    NumericMaskTextBoxProvider.GetFormat(numericMaskProvider.Mask, numericMaskProvider.Culture), _
                    Me.MaskedEditBoxElement))

    End Sub
End Class
0 comments