[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to limit the input values of a textbox for input values ¿¿between 1 and 500

Posted on 2011-09-12
7
Medium Priority
?
508 Views
Last Modified: 2013-12-17
how to limit the input values of a textbox for input values ¿¿between 1 and 500
0
Comment
Question by:abgconsulting
[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
  • 4
  • 2
7 Comments
 
LVL 18

Accepted Solution

by:
Cluskitt earned 2000 total points
ID: 36522437
Add code to the TextChanged event. Something like:

private void currencyTextBox_TextChanged(object sender, EventArgs e)
{
  if(Convert.ToInt32(currencyTextBox.Text) < 1 || Convert.ToInt32(currencyTextBox.Text)>500)
  {
    TextBox.Text = '0';
  }
}
0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 36522444
BTW, you might want to add a try/catch block, or some other validation, before doing the Convert.ToInt32. If there's a string in there, or some non-valid Int32 value, it will generate an error.
But that was just so you could see a way to do so.

You can also add the same validation on the submit button, or some such.
0
 

Author Comment

by:abgconsulting
ID: 36522523
Thx CLuskitt
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 18

Expert Comment

by:Cluskitt
ID: 36522563
Glad to help :)
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 36523529
You could also use a NumericUpDown control instead of a textbox. Then you can put the max and min in the properties. Sometimes those look better for numbers and it will automatically prevent anything but digits from going into the box.
0
 
LVL 18

Expert Comment

by:Cluskitt
ID: 36523568
I didn't suggest anything else because it depends on the environment being coded. For example, on ASP.Net you can use a MaskedEditExtender, a RangeValidator, etc.
0
 
LVL 37

Expert Comment

by:TommySzalapski
ID: 36524629
Sure. I wasn't saying there was anything wrong with your solution at all. Since the zone was C# and C#.NET I assumed it's a Windows Forms Application. I should have explicitly stated my assumptions, but most .NET environments have built in ways to hande ranged integer input so I thought I'd throw that out there in case it was helpful to someone.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

656 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