Reputation: 7
How would I make use of the Tags property of a node, so that I can get the attributes of an xml node?
I have to display an xml tree in a Windows Form. When I click on any node, its attributes should get displayed on a list box in same form.
I want to make use of tags property, but I need to convert that tree node in the form into an xml node. I wanted to store the tree node in the tag and then typecast that tag to an xml node.
How can I accomplish this?
Upvotes: 0
Views: 267
Reputation: 74530
When adding the TreeNode class, your code would look like this:
// Create the node.
TreeNode newNode = new TreeNode();
// Configure.
...
// Set the tag property to hold the XML element.
XmlElement currentElement = ...;
newNode.Tag = currentElement;
// Add to the tree view.
...
Then when you have the tree view node, you would get the element like this:
TreeNode currentNode = ...;
// Get the XmlElement.
XmlElement currentElement = (XmlElement) currentNode.Tag;
// Process the element.
...
Upvotes: 1