|
-
Feb 10th, 2020, 05:04 PM
#1
Thread Starter
Lively Member
VB.net WinForms Control Validation not working
Last edited by wjburke2; Feb 10th, 2020 at 05:16 PM.
-
Feb 10th, 2020, 05:19 PM
#2
Re: VB.net WinForms Control Validation not working
Don't post pictures of code. Code is text. Post it as text and format it as code. That way, we can read it easily and we can also copy and paste it. Also, provide steps that we can reproduce your issue, e.g. tell us what you entered where and when and what values you expected to see where and when and what values you actually see. The Validating event works for thousands of people the world over so, if it's not working for you, either you're doing something wrong or something is broken on your system. Either way, we can't diagnose the issue without knowing exactly what you're doing.
-
Feb 11th, 2020, 08:42 AM
#3
Thread Starter
Lively Member
Re: VB.net WinForms Control Validation not working
Actually this is a known bug. MSDN was able to recreate the issue and has given me a work around. One must disable and then enable the control in order to get the program buffer to update. My final code is below. JM, Thanks for your reply. I know you have much experience and I always value your input.
Code:
Private Sub dtpSL_LogIn_Date_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles dtpSL_LogIn_Date.Validating
' Fires on leave the control with/without changes
' Fires when record changes
' The program buffer does not contain the value in the control
' Disable and enable the control seems to get the current value
dtpSL_LogIn_Date.Enabled = False
dtpSL_LogIn_Date.Enabled = True
If dtpSL_LogIn_Date.Value = Save_SL_LogIn_Date Then
Exit Sub
End If
End Sub
Last edited by wjburke2; Feb 11th, 2020 at 08:50 AM.
-
Feb 11th, 2020, 08:45 AM
#4
Thread Starter
Lively Member
Re: VB.net WinForms Control Validation not working
Last edited by wjburke2; Feb 11th, 2020 at 08:51 AM.
-
Feb 11th, 2020, 02:06 PM
#5
Re: VB.net WinForms Control Validation not working
 Originally Posted by wjburke2
Actually this is a known bug. MSDN was able to recreate the issue and has given me a work around. One must disable and then enable the control in order to get the program buffer to update. My final code is below. JM, Thanks for your reply. I know you have much experience and I always value your input.
Code:
Private Sub dtpSL_LogIn_Date_Validating(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles dtpSL_LogIn_Date.Validating
' Fires on leave the control with/without changes
' Fires when record changes
' The program buffer does not contain the value in the control
' Disable and enable the control seems to get the current value
dtpSL_LogIn_Date.Enabled = False
dtpSL_LogIn_Date.Enabled = True
If dtpSL_LogIn_Date.Value = Save_SL_LogIn_Date Then
Exit Sub
End If
End Sub
You say this code works the way you want? I must be missing something because it doesn't look like that code does anything. No matter what the value in the dtp it just exits the Validating sub without doing anything.
-
Feb 11th, 2020, 02:31 PM
#6
Thread Starter
Lively Member
Re: VB.net WinForms Control Validation not working
You are right, I just put that in there so I could stop the program and check the value. My final code ended up being
Code:
Private Sub dtpSL_LogIn_Date_Validating(sender As Object, e As ComponentModel.CancelEventArgs) Handles dtpSL_LogIn_Date.Validating
' Fires on leave the control with/without changes
' The control value dose not contain the value in the control
' Disable and Enable the control seems to get the current value
dtpSL_LogIn_Date.Enabled = False
dtpSL_LogIn_Date.Enabled = True
' Fires when record changes (This skips validate on position change)
If tbSL_Shift_Key.Text <> Save_SL_ShiftKey Then
Exit Sub
End If
' Only want to validate if value changed.
If dtpSL_LogIn_Date.Value <> Save_SL_LogIn_Date Then
Validate_LogIn_Date()
End If
End Sub
Last edited by wjburke2; Feb 11th, 2020 at 02:39 PM.
-
Feb 11th, 2020, 03:35 PM
#7
Re: VB.net WinForms Control Validation not working
You need to look in the CancelEventArgs...

Setting e.Cancel = True if an invalid value is entered won't allow the user to leave the control until a valid value is entered
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|