in above project that attached, I change AutoValidate property of form1 to EnablePreventFocusChange. then I overrides onvalidating and onvalidated events at end of SHDataGridViewTextBoxEditingControl class
now validation on my customcolumn work fine but when I click by mouse to move to another cell , validating event fired 1 time and prevent to move and when I press tab key or enter , validating fired 2 time and move to another cell whitout prevent!. how solve it to fire only one time by press tab key ?
Code:Protected Overrides Sub OnValidating(e As CancelEventArgs) If AllowNull = False Then If String.IsNullOrEmpty(Me.Text.Trim) = True Then e.Cancel = True ' show message that cell value can not be null MessageBox.Show("لطفاً اطلاعات را وارد نمائید", "ارزیابی اطلاعات", MessageBoxButtons.OK, MessageBoxIcon.Information) Exit Sub End If Select Case InputType Case Inputs.NationalCode If ValidateNcode(Me.Text.Trim) = False Then e.Cancel = True 'show message that nationalcode is not in correct format MessageBox.Show("لطفاً کد ملی را بصورت صحیح وارد نمائید", "ارزیابی اطلاعات", MessageBoxButtons.OK, MessageBoxIcon.Information) End If Case Inputs.Numbers If AllowNegative = True Then If ismatched(Me.Text.Trim, negshregex) = False Then e.Cancel = True 'show message that integer number length limit to 15 and decimal numbers maximum length is 3 for example 123456789012345.123 MessageBox.Show("فرمت اعداد صحیح نمی باشد" & vbNewLine & "حداکثر طول اعداد صحیح 15 رقم" & vbNewLine & "و حداکثر طول اعداد اعشار سه رقم می باشد", "ارزیابی اطلاعات", MessageBoxButtons.OK, MessageBoxIcon.Information) End If Else If ismatched(Me.Text.Trim, shregex) = False Then e.Cancel = True 'show message that integer number length limit to 15 and decimal numbers maximum length is 3 for example 123456789012345.123 MessageBox.Show("فرمت اعداد صحیح نمی باشد" & vbNewLine & "حداکثر طول اعداد صحیح 15 رقم" & vbNewLine & "و حداکثر طول اعداد اعشار سه رقم می باشد", "ارزیابی اطلاعات", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End If Case Inputs.Decimals If AllowNegative = True Then If ismatched(Me.Text.Trim, negshregex) = False Then e.Cancel = True 'show message that integer number length limit to 15 and decimal numbers maximum length is 3 for example 123456789012345.123 MessageBox.Show("فرمت اعداد صحیح نمی باشد" & vbNewLine & "حداکثر طول اعداد صحیح 15 رقم" & vbNewLine & "و حداکثر طول اعداد اعشار سه رقم می باشد", "ارزیابی اطلاعات", MessageBoxButtons.OK, MessageBoxIcon.Information) End If Else If ismatched(Me.Text.Trim, shregex) = False Then e.Cancel = True 'show message that integer number length limit to 15 and decimal numbers maximum length is 3 for example 123456789012345.123 MessageBox.Show("فرمت اعداد صحیح نمی باشد" & vbNewLine & "حداکثر طول اعداد صحیح 15 رقم" & vbNewLine & "و حداکثر طول اعداد اعشار سه رقم می باشد", "ارزیابی اطلاعات", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End If End Select End If MyBase.OnValidating(e) End Sub Protected Overrides Sub OnValidated(e As EventArgs) MyBase.OnValidated(e) End Sub




Reply With Quote