Here's my code, the CurrencyValidate only fires when you leave with the mouse:
Public
Inherits System.Windows.Forms.DataGridTextBoxColumn
Dim TB As System.Windows.forms.TextBox
Public Sub New()
MyBase.New()
TB = Me.TextBox
TB.CausesValidation = True
AddHandler TB.KeyPress, AddressOf CurrencyKeyPressAddHandler TB.Validating, AddressOf CurrencyValidatingEnd SubProtected Sub CurrencyValidating(ByVal Sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)Dim Val As DecimalTryVal =
Decimal.Parse(TB.Text)Catch ex As ExceptionVal = 0
End TryTB.Text = Microsoft.VisualBasic.Format(Val, "0.00")
End SubProtected Sub CurrencyKeyPress(ByVal Sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)Dim keyascii As Integerkeyascii = Asc(e.KeyChar)
Select Case keyasciiCase 45, 46, 48 To 57, 8, 13 'numbers, decimal, backspace, return, minusCase Elsekeyascii = 0
End SelectIf keyascii = 0 Thene.Handled =
TrueElsee.Handled =
FalseEnd IfEnd SubEnd
ClassJust to ensure we are clear ... CausesValidation is a very odd property. When you set CausesValidation to true for the text box, it means that when the text box gets focus that the PRIOR control that had focus will have its Validating event generated. So it does not matter if the text box you have has CausesValdation set - but rather if the NEXT control in the TAB order has it set.
To put this in context, this should be set to True for every control but the Cancel button (or similar controls). The idea is that if the user clicked on Cancel that the prior controls would NOT get validated because the user just cancelled.
Hope this helps...