c# - TypeConverter IsValid not fireing -
i want implement input validation on propertygrid
. i've figured out need typeconverter
, throw exception in convertfrom
method. works fine except shows standard "message box". wish show own. according msdn exception catched in isvalid
method. i've tried override thing there doesn't fire.
my code:
public class parameternameconverter : typeconverter { public override object convertfrom(itypedescriptorcontext context, cultureinfo culture, object value) { debug.print("convertfrom"); if (convert.tostring(value).contains(" ")) { throw new notsupportedexception("invalid input"); } return value; } public override bool isvalid(itypedescriptorcontext context, object value) { messagebox.show("invalid input"); return false; } }
this code isvalid()
microsoft reference source. can see isvalid()
calls convertfrom()
, try catches it. need perform similar operation calling own convertfrom()
method own isvalid()
method, , handle exception. if don't override isvalid()
base method isvalid()
silently eat exception
, return standard false
response.
although sounds me isvalid()
method never being called @ if you're not seeing own message box pop example code? that's different question :p
Comments
Post a Comment