开发者

Localize node texts in treeview using resource files

开发者 https://www.devze.com 2022-12-24 16:55 出处:网络
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 fil

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.Ge开发者_StackOverflow中文版tString(node.Name + "_Text");
        this.TranslateNodes(node.Nodes);
    }
}

Thanks!


Your approach looks ok for me, with one exception, it believes that node.Name is unique though entire treeview (which is not correct in general case).

You can use TreeNode.FullPath for unique identify node within treeview. Or alternatively your code can depend on node tag value, but this is highly depend on usage scenario.

And do not forget about calling TreeView's BeginUpdate-EndUpdate.


No suitable, solution found except the one statete in the op ... so closing the question seems apropriate.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号