Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing DescriptionAttribute in Propertygrid at runtime

Status
Not open for further replies.

HavardH

Programmer
Aug 6, 2007
1
NO
Hello

I am working on a project where we use a propertygrid to present some data. We have added globalization, including a custom DescriptionAttribute class:

Code:
[AttributeUsage(AttributeTargets.Property)]
public sealed class LanguageKeyDescriptionAttribute : DescriptionAttribute
{
private string _key;
private ILanguageProvider _lang = LanguageProvider.Singleton;

public string Key
{
get { return _key; }
}

public LanguageKeyDescriptionAttribute(string key)
{
this.DescriptionValue = _lang.GetItem(key);
_key = key;
_lang.LanguageChanged += new EventHandler<EventArgs>(lang_LanguageChanged);
}

private void lang_LanguageChanged(object sender, EventArgs e)
{
this.DescriptionValue = _lang.GetItem(_key);
}
}
The LanguageProvider class simply takes care of the mapping to the resource table belonging to the current selected language. It offers an event, LanguageChanged, which is fired whenever the user requests that a new language.

The LanguageKeyDescriptionAttribute only works to a certain extent; the descriptions are displayed in whichever language that is selected the first time an attribute with that key is displayed in the propertygrid, for the lifetime of the application. This is quite annoying, because if the user changes language halfway through a session, the propertygrid will most likely consist of a mix of property descriptions in different languages.

If I have to guess, I suppose this is caused by something like .NET or the PropertyGrid control only loads these attributes once per key passed to the constructor, and caches the description values for later use even if the actual instance is updated (the event listener works fine and actually changes value of DescriptionValue as it should, its just the propertygrid that doesnt display these changes).

Any solutions to this would be greatly apreciated.


Best regards,
Havard H
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top