469,643 Members | 2,061 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

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

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.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/
Jul 21 '06 #1
2 1080
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
---------

"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:Ol**************@TK2MSFTNGP02.phx.gbl...
>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.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

Jul 21 '06 #2
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.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"G Himangi" <in**@ssware.comwrote in message
news:em**************@TK2MSFTNGP04.phx.gbl...
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
---------

"Nathan Sokalski" <nj********@hotmail.comwrote in message
news:Ol**************@TK2MSFTNGP02.phx.gbl...
>>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.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/


Jul 21 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Hernán Castelo | last post: by
7 posts views Thread by Paul | last post: by
4 posts views Thread by owingruters | last post: by
3 posts views Thread by Martin | last post: by
4 posts views Thread by Jon Paal | last post: by
11 posts views Thread by jjbutera | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.