看板 C_Sharp 關於我們 聯絡資訊
目的:將資料庫的節點資料,動態生成樹狀圖 問題:請問在TreeView中,如何判斷是否已經存在某名稱的節點? 比如說我有個Root:net:good:morning 的節點 還有個: Root:net:good:afternoon 的節點 但是我在TreeView中畫出的圖形,應該是只有最後的morning和afternoon是二個葉節點,其它是同一個支幹 目前試了很多方法都失敗 例如: TreeNode rootNode = new TreeNode(); rootNode.text= "net"; rootNode.value ="net"; 利用下面二個方式來作判別都失敗 treeView.nodes.contains(rootNode) //這個說要valuePath,不是很懂 treeView.FindNode(rootNode.valuePath) 以下是目前的錯誤程式碼片段: string nodeOfTreeView = path[depth]; if ( nodeOfTreeView != null) { if (depth == 0) { rootNode.Text = nodeOfTreeView; rootNode.Value = nodeOfTreeView; rootNode.NavigateUrl = @"./ShowComponentDetails.aspx?Name=" + nodeOfTreeView; if (TreeViewOfPath.FindNode(rootNode.ValuePath) != null) { // Indicate that the node was found. showMsg("The specified node (" + rootNode.ValuePath + ") was found."); } else { // Indicate that the node is not in the TreeView control. showMsg("The specified node (" + nodeOfTreeView + ") is not in this TreeView control."); showMsg("new rootNode =" + rootNode.Value); TreeViewOfPath.Nodes.Add(rootNode); } ... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.77.241.1
jiing24:我有節點的名稱,能否判斷treeview中是否有相同名稱的節點 04/25 19:32