Hello
I am trying to write a customEditor for a gridview to handle "rapid" data entry for grade values.
The grade values can be from 0 to 10 in steps of 0.5 (valid values are, for instance, 4 or 4.5, but not 4.1)
I wish to be able to type in the grades on the numerical keypad and on the main keyboard
where:typing a single character numeric value sets the value typed
and typing CTRL-num value sets the "halfed grade" (ex: type CTRL-4 for obtaining 4.5)
furthermoreI need to have the cursor positioned to the cell below imediately after the entry validation
The columns are currently text columns but could be numerical columns
I have tried using the followind code and Custom Editor:
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub gvMark_EditorRequired(sender As Object, e As EditorRequiredEventArgs) Handles gvMark.EditorRequired
If e.EditorType Is GetType(RadTextBoxEditor) Then
e.EditorType = GetType(MarkEditor)
End If
End Sub
Public Class MarkEditor
Inherits RadTextBoxEditor
Public Property Value As Object
Get
Dim Editor As RadTextBoxEditorElement = CType(EditorElement, RadTextBoxEditorElement)
Return Editor.Text
End Get
Set(value As Object)
Dim Editor As RadTextBoxEditorElement = CType(EditorElement, RadTextBoxEditorElement)
If value IsNot Nothing Then
Editor.Text = Convert.ToString(value)
Else
Editor.Text = ""
End If
End Set
End Property
Public Overrides Sub BeginEdit()
MyBase.BeginEdit()
Me.EditorElement.Focus()
Dim EditorElement As RadTextBoxEditorElement = CType(Me.EditorElement, RadTextBoxEditorElement)
AddHandler EditorElement.KeyDown, AddressOf Element_KeyDown
End Sub
Public Overrides Function EndEdit() As Boolean
MyBase.EndEdit()
Me.EditorElement.Focus()
Dim EditorElement As RadTextBoxEditorElement = CType(Me.EditorElement, RadTextBoxEditorElement)
RemoveHandler EditorElement.KeyDown, AddressOf Element_KeyDown
Return MyBase.EndEdit
End Function
Private Sub Element_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs)
Try
Dim KeyChar As String = fromKeyCode(e.KeyCode)
If Not e.Control Then
Value = KeyChar
Else
Value = KeyChar & ".5"
End If
Catch ex As Exception
End Try
End Sub
Public Function fromKeyCode(KeyCode As Integer) As String
'returns the caracters 0..9 for Keyboard Keys 0..9 and NumPadKeys 0..9 and "*" from NumPad "Multiply"
Try
If KeyCode >= 48 And KeyCode <= 57 Then '0..9 Keyboard
Return (KeyCode - 48)
ElseIf KeyCode >= 96 And KeyCode <= 105 Then '0..9 NumPad
Return (KeyCode - 96)
ElseIf KeyCode = 106 Then '* NumPad
Return "*"
Else
Return ""
End If
Catch ex As Exception
Return ""
End Try
End Function
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I have a strange result (same result when using the keyboard or the numeric pad)
1. if I type a single numeric value -> it is displayed twice in the cell, i.e.if I type 4 I see 44 and the cursor is in the middle of the two characters
2. if I type CTRL-4 I get the desired 4.5 string in the cell
3. I have tried to add a sendkeys.send(vbcr) at different places (valueChanged, CellvalueChanged events unsuccessfully) to move the focus to the cell below
(Ultimately I'll have to do more advanced data validation based on other criterias)
Thanks in advance for any suggestion
Best Regards