Home All Groups Group Topic Archive Search About

Validating a "PropertyGrid" row

Author
28 Feb 2007 1:03 AM
John Brown
Hi there,

I've got an "int" property in one of my objects that I need to conduct a
range check on in a "PropertyGrid" (whenever the user attempts to leave the
row). I know how to do this using the "TypeConverterAttribute" for
user-defined types but I'm not sure how to handle it for built-in types like
an "int". Can anyone provide any insight. Thanks.

Author
4 Mar 2007 2:51 PM
Oliver Sturm
Hello John,

>I've got an "int" property in one of my objects that I need to conduct a
>range check on in a "PropertyGrid" (whenever the user attempts to leave
>the row). I know how to do this using the "TypeConverterAttribute" for
>user-defined types but I'm not sure how to handle it for built-in types
>like an "int". Can anyone provide any insight. Thanks.

If your property can only be set to ints in a certain value range, you
should be throwing an exception from the property setter, right? This is
automatically evaluated by the PropertyGrid and an error dialog shown.


                Oliver Sturm
Author
4 Mar 2007 5:45 PM
John Brown
> If your property can only be set to ints in a certain value range, you
> should be throwing an exception from the property setter, right? This is
> automatically evaluated by the PropertyGrid and an error dialog shown.

Thanks very much. I didn't realize it was that simple. After working with
the "PropertyGrid" for several weeks now, I've seen no documentation
whatsoever that indicated this. Now that I'm actually looking at the
"PropertyDescriptor.SetValue" method in MSDN however, it does in fact
mention it (though no mention is made of the "PropertyGrid"). In any case,
thanks again (appreciated).

AddThis Social Bookmark Button