Thank you Greg !!!! You saved my day, Infragistics please hire Greg!
This works for me:
private void dueDateUltraDateTimeEditor_AfterEnterEditMode(object sender, EventArgs e){
dueDateUltraDateTimeEditor.PerformAction(Infragistics.Win.UltraWinMaskedEdit.
MaskedEditAction.ToggleInsertionMode, false, false);
}
Here is the syntax: I put this in the Enter event...
Dim numericeditor As Infragistics.Win.UltraWinEditors.UltraNumericEditor = sender
numericeditor.BeginInvoke(New MethodInvoker(AddressOf numericeditor.SelectAll))
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