0
我有一個用戶無法編輯的Treeview。我試圖刷新的方式是清除整個樹並重新添加所有節點(和子節點)。我通過以下幾行代碼實現這一點:Treeview刷新問題
treeView.BeginUpdate(); //Freeze drawing
treeView.Nodes.Clear(); //Empty Tree
addAllNodes(); //This adds the nodes for the tree and sets their name/text property
treeView.EndUpdate(); //Unfreeze drawing
我試着添加更新和刷新方法之前,我打電話addAllNodes但還沒有做出區別。上述這樣得到我的錯誤:
System.ArgumentException: Cannot add or insert the item 'NodeNameHere' in more than one place. You must first remove it from its current location or clone it
我的第一個問題是,我在做什麼造成這個錯誤,我怎麼能正確刷新我的樹?
我的第二個問題是,刷新後有什麼辦法可以恢復用戶的擴展節點? (這樣一切都不會崩潰)
至於第二個問題,我爲此做了什麼之前,我清除我的樹視圖,我遍歷節點,如果該節點展開,我將該節點添加到列表。然後,清除並添加節點,並遍歷我的列表,展開列表中的節點。 – seekerOfKnowledge 2011-04-27 18:09:43
我正在接近這個錯誤的方式。我繼續前進,只清理需要更新的孩子。任何靜態節點(從addAllNodes()添加都不需要觸摸)。仍然想要記住所有擴展節點的方法。 – Demasterpl 2011-04-27 20:03:56
@John Arlen - 是的,一次通過調試線,樹被清除。 – Demasterpl 2011-04-27 20:07:18