How do I validate the values entered for custom control properties?

N

Nathan Sokalski

I have a custom control with properties named MinValue, MaxValue, and Value
(all of which I have assigned a DefaultValue design-time attribute). The
Value property must be between (or equal to) the MinValue and MaxValue
properties in order to avoid a runtime error. I want to give an error during
the usage of the control stating this, as well as prevent it from compiling
under these conditions. Because this is something I have never done with
custom controls before, I need some help here. Thanks.
 
G

G Himangi

One way would be to throw an exception if the value is out of range - Visual
Studio will catch this exception and not allow the user to change to invalid
values.


---------
- G Himangi, Sky Software http://www.ssware.com
Shell MegaPack : Drop-In Explorer GUI Controls For Your Apps (.Net & ActiveX
Editions Available)
EZNamespaceExtensions.Net : Develop namespace extensions rapidly in .Net
EZShellExtensions.Net : Develop all shell extensions rapidly in .Net
 
N

Nathan Sokalski

That will not work in all situations. For example, if the current values are
MinValue=75, MaxValue=100, Value=80 and the user wants to change them to
MinValue=25, MaxValue=50, Value=40. This will force the user to change them
in a certain order, which could be very annoying. I want the user to be
notified, but still be allowed to change them, and simply not be allowed to
compile it if they are out of range. Also, if I did use your exception idea,
where in my code would I put it? Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top