Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

NumericUpDown control

Posted on 2004-09-20
3
Medium Priority
?
346 Views
Last Modified: 2008-02-26
Quick Question.

Is there a setting or code to prevent someone from typing over the maximum value set for a NumericUpDown control.
If the max is set to 100 you cant scroll pass but you can type whatever ou want...

Thanks in Advance for the Info.
0
Comment
Question by:swilli6926
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 6

Accepted Solution

by:
KGreg earned 200 total points
ID: 12105757
put this in the keypress event or the numeric editor (mine was named num):

        If Val(num.Text + e.KeyChar.ToString) > num.Maximum Then
            num.Value = num.Maximum
            num.Text = num.Maximum.ToString
            e.Handled = True
        End If

KGreg
0
 
LVL 5

Expert Comment

by:tzxie2000
ID: 12105770
you can type in number bigger than the max
but when you get value you will find the value is set to the max
0
 

Expert Comment

by:St_Rand
ID: 26005641
KGreg, you are not quite right.  You must consider the placement of the cursor.  For example if the maximum value allowed is 45, follow this example:
1. there is one number entered already. Let's say its 3
2. The user then puts the cursor before the 3 and types a 5.  The resulting value would be 53, which is greater than the maximum value allowed, BUT your code If Val(num.Text + e.KeyChar.ToString) > num.Maximum  would test "35" and allow the keystroke.  You need to do something like this:
    Private Sub num_KeyPress(ByVal sender As Object,   _
         ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles num.KeyPress
         Dim s As String
         s = num.Text
         'place the pressed character into the
          'proper position within the text - then you can test for maximum value.
         s = s.Insert(num.SelectionStart, e.KeyChar.ToString)
              If Val(s + e.KeyChar.ToString) > num.Maximum Then
                  num.Value = num.Maximum
                  num.Text = num.Maximum.ToString
                  e.Handled = True
             End If
    End Sub
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question