Reputation: 6778
I have code like so (simplifying for the question):
public const string THIS_AND_THAT = "This & That";
System.Windows.Forms.GroupBox myGroupBox;
System.Windows.Forms.TreeView myTreeView;
System.Windows.Forms.TreeNode myTreeNode;
myGroupBox.Text = THIS_AND_THAT;
myTreeNode = new TreeNode(THIS_AND_THAT);
myTreeNode.Name = THIS_AND_THAT;
myTreeView.Nodes.Add(THIS_AND_THAT);
With this code, the GroupBox
displays as "This That" and the TreeView
displays correctly as "This & That".
So I changed the string (as suggested here) to this:
public const string THIS_AND_THAT = "This && That";
In this case, the GroupBox
displays correctly as "This & That", but the TreeView
displays as "This && That".
I don't see that I can use UseMnemonic Property on the GroupBox or TreeView.
What do I do?
Upvotes: 1
Views: 353
Reputation: 155418
(Promoting my comment to an answer):
There is inconsistency in how different controls in Windows and WinForms handle strings displayed to the user, as you've discovered TreeView
does not support escaped ampersands while GroupBox
does.
Fortunately it's straightforward to provide appropriate text:
String text = "This && that";
myGroupBox.Text = text;
myTreeNode.Text = text.Replace("&&", "&");
Upvotes: 1