2009-03-02 101 views
0

我将如何利用节点的Tags属性,以便我可以获取xml节点的属性?如何利用xml节点的Tags属性来获取其信息和属性?

我必须在Windows窗体中显示一个xml树。当我点击任何节点时,其属性应以相同的形式显示在列表框上。

我想使用标签属性,但我需要将表单中的树节点转换为xml节点。我想将树节点存储在标记中,然后将该标记转换为xml节点。

我该如何做到这一点?

回答

1

当添加树节点类,你的代码应该是这样的:

// 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. 
... 

然后当你有树视图节点,你会得到这样的元素:

TreeNode currentNode = ...; 

// Get the XmlElement. 
XmlElement currentElement = (XmlElement) currentNode.Tag; 

// Process the element. 
... 
+0

可以ü请填补你的空白?并且还可以获取我使用事件处理函数treeview_AfterSelect的属性,所以你的代码的第二部分会写在那里? – user72731 2009-03-02 20:16:49