Hi Keith,
Thanks for your post!
From your description, my understanding now is,
You wrote a component and it will throw exception when receiving an invalid
value. You would like to localize this message, so you want to catch this
exception in propergrid component and localize this message on your own.
Based on my research, You may try the following two ways to customize this
message:
1. From the object side, you may derive from your component and write a
wrapper for your component, catch all the exceptions and change them to the
localized message and rethrow them. It might be cleaner solution, since you
only need write a class and all codes are centralized.
2. From the PropertyGrid side, there is no direct way to "Intercept" such
exception, however you may define a typeconverter and added to your
properties, then override the CanConvertFrom method like below;
<code>
public override object ConvertFrom(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value)
{
try
{
//give a new culture to get
return base.ConvertFrom (context, culture, value);
}
catch (UserException ex)
{
//get localized version of ex.Message
throw new Exception("Localized message",ex);
}
}
</code>
Also, if you just want to localize the exception message of .NET defined
exceptions, you may install the language pack and set the
hread.CurrentThread.CurrentUICulture to that locale before base.ConvertFrom
like:
<code>
Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN",true);
</code>
We will localize all the other text to your culture.
Does my suggestions solve your problem?
Please let me know if you have any further questions on this issue, Thanks!
Best regards,
Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, "online" should be removed before
sending.