[問題] 請問在TreeView中,如何判斷是否已經存在某名稱的節點?

看板C_Sharp (C#)作者 (jiing)時間18年前 (2007/04/25 12:24), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
目的:將資料庫的節點資料,動態生成樹狀圖 問題:請問在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

04/25 19:32, , 1F
我有節點的名稱,能否判斷treeview中是否有相同名稱的節點
04/25 19:32, 1F
文章代碼(AID): #16BjVYn_ (C_Sharp)
文章代碼(AID): #16BjVYn_ (C_Sharp)