Validating a "PropertyGrid" row

  • Thread starter Thread starter John Brown
  • Start date Start date
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.
 
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
 
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).
 
Back
Top