Last Updated: 14 Jun 2018 14:43 by Dimitar
Dess | Tech Support Engineer, Principal
Created on: 24 May 2018 06:46
Category: Editors
Type: Bug Report
FIX. RadDateTimePicker - time part is not selected any more with the mouse once the AM/PM part has been selected
To reproduce:       
 Me.RadDateTimePicker2.Format = DateTimePickerFormat.Custom
 Me.RadDateTimePicker2.CustomFormat = "hh:mm tt"

Select the hours part with the mouse, the selection is affected correctly. Select the minutes part, the selection is affected correctly. Select the AM/PM part, the selection is again affected correctly. Now, try to select again the minutes part. You will notice that the cursor is affected correctly but the selection is missing. Once you select the AM/PM part then the selection is not updated properly with the mouse anymore.


Me.RadDateTimePicker1.DateTimePickerElement.TextBoxElement.Provider = New CustomMaskDateTimeProvider(Me.RadDateTimePicker2.DateTimePickerElement.TextBoxElement.Mask, Me.RadDateTimePicker2.Culture, Me.RadDateTimePicker2.DateTimePickerElement.TextBoxElement)

    Public Class CustomMaskDateTimeProvider
        Inherits MaskDateTimeProvider

        Public Sub New(mask As String, culture As CultureInfo, owner As RadMaskedEditBoxElement)
            MyBase.New(mask, culture, owner)

        End Sub
        Public Overrides Function SelectCurrentItemFromCurrentCaret() As Boolean
            Dim currentSelection As Integer = Me.TextBoxItem.SelectionStart
            Dim currentPos As Integer = 0
            Dim selected As Boolean = False

            'If Me.List(Me.SelectedItemIndex).type = PartTypes.AmPm Then
            '    Return True
            'End If

            For i As Integer = 0 To Me.List.Count - 1
                Dim part As MaskPart = Me.List(i)

                If SelectMilliseconds(i, part) Then
                    Exit For
                End If

                If currentSelection >= part.offset AndAlso currentSelection <= part.offset + part.len AndAlso Not part.[readOnly] AndAlso part.type <> PartTypes.Character Then
                    Me.TextBoxItem.SelectionStart = Me.List(i).offset
                    Me.TextBoxItem.SelectionLength = Me.List(i).len
                    Me.SelectedItemIndex = i
                    selected = True
                    Exit For
                End If

                currentPos += part.len

            Return selected
        End Function

        Private Function SelectMilliseconds(ByVal i As Integer, ByVal part As MaskPart) As Boolean
            If part.type = PartTypes.MiliSeconds AndAlso Me.value.Millisecond Mod 10 = 0 AndAlso part.trimsZeros Then
                Dim newLen As Integer = part.len

                For power As Integer = 1 To part.len

                    If Me.value.Millisecond Mod Math.Pow(10, power) = 0 Then
                        newLen -= 1
                        Exit For
                    End If

                Me.textBoxItem.SelectionStart = Me.list(i).offset
                Me.textBoxItem.SelectionLength = newLen
                Me.SelectedItemIndex = i
                Return True
            End If

            Return False
        End Function
    End Class