2009-03-02 43 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