Hi Klemens,
It sounds like what you need to do is select all of the text in the field. I would try handling the Enter event of the control(s) and calling the SelectAll method to select all of the text. Or if there is no SelectAll method, set SelectionStart and SelectionLength.
I am struggling with this same date overwrite problem myself, the question I have is: why having spent all this money, do my new Infragistics controls work worse than the free MS one? Sure, I can override everything and fix it, but that is a pain. Selecting the text is not the answer really. If my insert point is at the start of "2005" and I type "2008" I expect something sensible, not nothing at all. Surely this is because you have a simple masked edit field and not a proper date time control !
It seems to me that Infragistics are guilty of chasing headline features, and not addressing some basic deficencies. Others include no support for dddd dd/mm/yyyy style formats, and listviews that don't select items on right click. These are small things, but ones that MS has put right over the years, and I would have expected you to at least provided a switch to enable this sort of functionality. I am rapdily ending up subclassing all my controls to fix these problems.
4/10 must try harder.
Here's what I used to replace the UltraTextEditor control so that it detects whether you are in Insert or Overtype mode and works accordingly (read using GetKeyState in user32.dll) - sorry about the formatting - I've used CODE tags but they don't work very well??
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Integer) As Integer Private Const INSERT_KEY As Integer = 45 Friend Shared Function InsertMode() As Boolean Return CType(GetKeyState(INSERT_KEY), Boolean) End Function Public Class UltraTextEditorCl Inherits UltraTextEditor Private Sub UltraTextEditorCl_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Me.KeyPress TryDim dt As DateTime = DateTime.Now Dim tb As UltraTextEditorCl = CType(sender, UltraTextEditorCl)If (Not InsertMode()) _ AndAlso (AscW(e.KeyChar) >= 32) _AndAlso (tb.SelectionLength = 0) _ AndAlso (tb.SelectionStart < tb.Text.Length) Then If tb.Text.Substring(tb.SelectionStart, 1) <> Environment.NewLine Then tb.SelectionLength = 1 End If End IfCatch ex As Exception HandleException(ex) End Try End Sub
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Integer) As Integer
Private Const INSERT_KEY As Integer = 45
Friend Shared Function InsertMode() As Boolean
Return CType(GetKeyState(INSERT_KEY), Boolean)
End Function
Inherits UltraTextEditor
Try
Dim tb As UltraTextEditorCl = CType(sender, UltraTextEditorCl)
AndAlso (AscW(e.KeyChar) >= 32) _
AndAlso (tb.SelectionStart < tb.Text.Length) Then
If tb.Text.Substring(tb.SelectionStart, 1) <> Environment.NewLine Then tb.SelectionLength = 1 End If
If tb.Text.Substring(tb.SelectionStart, 1) <> Environment.NewLine Then
tb.SelectionLength = 1
End If
HandleException(ex)
End Try
End Sub
Here is my solution to the overwrite problem, in case it is of any use to anyone. It isn't entirely generic, but it seems to do the job for dd/MM/yyyy or similar. I still maintain Infragistics could manage a few lines like this on our behalf and save eveyone the bother.
Public Class ucDateTimeEditor Inherits Infragistics.Win.UltraWinEditors.UltraDateTimeEditor
Protected Overrides Sub OnKeyPress(ByVal e As System.Windows.Forms.KeyPressEventArgs) Dim c As String Dim sText As String Dim bIsSparePlaceHolder As Boolean Dim i As Integer Dim lStart As Integer
c = e.KeyChar
Select Case c Case "0" To "9" sText = Me.Text lStart = Me.SelectionStart
If lStart = sText.Length Then Exit Select ' at the end of field If Me.SelectionLength > 0 Then Exit Select ' characters selected If sText.Substring(lStart, 1) = "/" Then Exit Select ' on a separator
If lStart = sText.Length Then lStart = lStart - 1 For i = lStart - 1 To 0 Step -1 If sText.Substring(i, 1) = Me.PromptChar Then bIsSparePlaceHolder = True Exit For ElseIf sText.Substring(i, 1) = "/" Then Exit For End If Next
If Not bIsSparePlaceHolder Then For i = lStart To sText.Length - 1 If sText.Substring(i, 1) = Me.PromptChar Then bIsSparePlaceHolder = True Exit For ElseIf sText.Substring(i, 1) = "/" Then Exit For End If Next End If
If bIsSparePlaceHolder Then Exit Select
' we need to remove something to make this char fit. Me.Text = sText.Substring(0, lStart) & c & sText.Substring(lStart + 1) Me.SelectionStart = Me.SelectionStart + 1 e.Handled = True
End Select MyBase.OnKeyPress(e) End Sub
End Class