TreeView TreeNodeCollection Key

.net, c#, treeview, vb.net, winforms

Solution

Take a look here. In the remarks you'll find the following

The Name property corresponds to the key for a TreeNode in the TreeNodeCollection.

Problem

The TreeView uses in its underlying implementation the TreeNodeCollection. The TreeNodeCollection in almost every overload of the add method asks for a key. It also implements indexOfKey and ContainsKey yet there appears to be no way to determine the key of a node from the node itself or from any of the events you would typically use such as TreeView_AfterSelect(). Am I correct or is there in fact someway to retrieve the key from a node or event which I have overlooked? And assuming I am correct. Why on earth was it implemented in such a way? The only thing I could think of was that perhaps TreeNodeCollection.Key is deprecated? But I see no mention of this… PS: I am aware of the TreeNode.Tag property and how it can be used to the same effect.

Original source