Localize node texts in treeview using resource files

Posted by Obalix on Stack Overflow See other posts from Stack Overflow or by Obalix
Published on 2010-03-24T11:04:31Z Indexed on 2010/04/09 13:03 UTC
Read the original article Hit count: 387

For a project I need a tree view that allows the user to select a module, which then is displayed in a content area. The project relies heavily on localization and this is provided by the resource files.

Now I discovered today, that the text that are assigned to preset tree view nodes are not contained in the resource files.

So the question is whether there is a way of doing this, short of mapping the elemenst in code. I.e. assigning a name to the node, running over all nodes and pulling the resources from the resouce manager based on the node name.

This is what I am currently doing, however, it just doesn't "feel" right:

private void TranslateNodes(TreeNodeCollection treeNodeCollection) {
    var rm = Resources.ResourceManager;
    foreach (TreeNode node in treeNodeCollection) {
        node.Text = rm.GetString(node.Name + "_Text");
        this.TranslateNodes(node.Nodes);
    }
}

Thanks!

© Stack Overflow or respective owner

Related posts about c#

Related posts about .net-3.5