-
Jan 23rd, 2006, 09:52 PM
#1
Thread Starter
Addicted Member
Validation Event
I am developing an applicaiton that you can input auditing data to --> this updates a database and so on.
What happens is the user enters an integer/double value into a textbox using an inkedit. The input looks like ink for a second and then it is recognized. If the value is too low or too high, the textbox changes color, red or green (if value is within spec). The value is only validated if another textbox is activated. My problem is when the last valu is added a user has to find something to click to validate the text! I want to eliminate that inconvenience. Right now the validation header is this:
VB Code:
Private Sub FBR1_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles FBR1.Validating
I want to set it so it is validated when the text is recognized. Does that make sense??
thx in advance!!
Juri
-
Jan 23rd, 2006, 10:12 PM
#2
Re: Validation Event
I'm guessing that the TextChanged event will be raised when the ink is converted to text. The thing is, you have no guarantee that the user is going to enter the values in order. You'd have to use the TextChanged event for every control. You'd still want to use the Validating event though because it allows you to prevent the current control losing focus if its value is invalid. What usually happens is the last control is validated when the user clicks the OK button. If the control fails validation then it will not lose focus and the button click is not raised. You would usually have a Cancel button with its CausesValidation property set to False. This allows the user to click Cancel and exit without having the active control validated. Note that you can call the Validate method of the form at any time to raise the Validating on any controls that are awaiting validation.
-
Jan 23rd, 2006, 10:14 PM
#3
Thread Starter
Addicted Member
Re: Validation Event
Actually, now that I have thought about this for a little while. It would be nice if the form refreshed itself every second or so and every textbox with a validation event changed to reflect new data. For instance:
Highgloss paint cannot have a gloss reading that is below 80
Lowgloss paint can have any value.
I have a radio button on the same form that allows the user to select either highgloss paint or lowgloss paint. If the user selects highgloss then enters into the textbox 65, then the box would turn red. Now say the user changes the selection to lowgloss paint, the textbox would validate this and turn green.
Juri
-
Jan 23rd, 2006, 10:19 PM
#4
Re: Validation Event
Originally Posted by jmcilhinney
Note that you can call the Validate method of the form at any time to raise the Validating on any controls that are awaiting validation.
Note that you normally use the Validating event to prevent a control losing focus if it fails validation. If you do not intend to do that then it is more appropriate to use the Validated event. Calling Validate on a container control will raise the Validating then Validated event on every control that is awaiting validation.
-
Jan 24th, 2006, 06:19 PM
#5
Thread Starter
Addicted Member
Re: Validation Event
ok I used both the TextChanged event and the validating event, works beautifully! Thank you!
Juri
-
Jan 24th, 2006, 06:57 PM
#6
Re: Validation Event
Cool. Don't forget to resolve your thread from the Thread Tools menu.
-
Jan 24th, 2006, 07:03 PM
#7
Thread Starter
Addicted Member
Re: Validation Event
One thing I noticed, the program crashes if the user enters an letter instead of a number - my code:
VB Code:
If (FBL1.Text = " ") Or FBL1.Text = String.Empty Then
FBL1.Text = "0"
End If
Dim DblFBL1 As Double = Convert.ToDouble(FBL1.Text)
Dim StrPaintType As String = PaintType.Text
If (StrPaintType = "EA") Then
If VirginRadio.Checked Then
If (DblFBL1 < 2.0 Or DblFBL1 > 5.0) Then
FBL1.BackColor = Color.Salmon
Else
FBL1.BackColor = Color.LightGreen
End If
End If
If RepaintRadio.Checked Then
FBL1.BackColor = Color.LightGreen
End If
End If
If (StrPaintType = "EB") Then
If VirginRadio.Checked Then
If (DblFBL1 < 2.5 Or DblFBL1 > 5.0) Then
FBL1.BackColor = Color.Salmon
Else
FBL1.BackColor = Color.LightGreen
End If
End If
If RepaintRadio.Checked Then
FBL1.BackColor = Color.LightGreen
End If
End If
the crash happens at this line -
Dim DblFBL1 As Double = Convert.ToDouble(FBL1.Text)
Obviously because a letter cannot be converted into an integer, or in this cas a double. How can I prevent this? I have set the factoid for the box to only accept numerical inputs, however this is not 100%.
TIA Juri
-
Jan 24th, 2006, 07:06 PM
#8
Re: Validation Event
Look into the Double.TryParse method.
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
|