Validating a "PropertyGrid" row

J

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.
 
O

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
 
J

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).
 

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

Top