|
-
Jul 2nd, 2003, 05:51 AM
#1
Thread Starter
Frenzied Member
NumericUpDown validation
Hi,
I'm using a NumericUpDown control on a properties dialog. I've set the Max and Min limits to 1 and 250. The idea is that the user selects a value in that range, clicks the OK button and the value gets passed to the calling code.
The problem is this: If the user types in 999 (using the keyboard, not the spin buttons) then clicks ok the NumericUpDown control's text and value properties are both 250 and this is what gets passed to the calling code.
I need to find a way of trapping these invalid entries.
The two approaches I've already thought of (but don't like are these)
1. Make the control ReadOnly so that values can't be typed (or pasted) in directly
2. Monitor the ValueChanged / TextChanged events - I don't like this because if the user wants to change "100" to "110" it throws up an error message for a transitory "1100".
Any ideas?
This world is not my home. I'm just passing through.
-
Jul 2nd, 2003, 06:39 AM
#2
I wonder how many charact
Monitor the ValueChanged / TextChanged events - I don't like this because if the user wants to change "100" to "110" it throws up an error message for a transitory "1100".
Then just catch the error, and ignore it instead of showing an error message...and keep the old value instead..
-
Jul 2nd, 2003, 07:17 AM
#3
Thread Starter
Frenzied Member
RESOLVED
Thanks to nemaroller:
VB Code:
Private mblnAddressInvalid As Boolean
Private Sub nudAddress_TextChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles nudAddress.TextChanged
mblnAddressInvalid = _
CBool(Val(CType(sender, NumericUpDown).Text) < 1 OrElse _
Val(CType(sender, NumericUpDown).Text) > 250)
End Sub
Private Sub cmdOK_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles cmdOK.Click
If mblnAddressInvalid Then
MessageBox.Show(GetText("addressOutOfRange"), _
GetText("addressOutOfRangeTitle"), _
MessageBoxButtons.OK)
nudAddress.Focus()
Else
DialogResult = DialogResult.OK
End If
End Sub
This world is not my home. I'm just passing through.
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
|