我在ASP.NET 3.5 Web應用程序中使用TreeView和ShowCheckBoxes =「All」,出於某種原因,檢查的節點沒有按順序返回。比方說,我有節點A,B,C和我選擇B和C並點擊保存按鈕,當我檢查Treeview的CheckedNodes屬性時,檢查的節點按順序(B,C)。但下一次當我回到頁面並選擇節點A時,訂單正在返回B,C,A。什麼可能是這種行爲的原因?Treeview checked nodes not order in order
3
A
回答
2
CheckedNodes是剛剛實現ICollection的一個TreeNodeCollection。當checkChanged事件觸發時,它可能只是將樹節點添加到CheckedNodes集合中。
什麼我可以看到on MSDN意味着你應該承擔的節點將被訂購。所有它說的是:
每次網頁發佈到 服務器時,CheckedNodes收集 與 選擇的節點自動填充。
從您的實驗中,似乎可以安全地假設在第二次回發時,它只是將任何新的已檢查節點添加到集合中,而不是清除集合並重新添加所有內容。
0
一個簡單的例程來排序CheckedNodes
集合就足以解決這個問題。這個例程(http://urenjoy.blogspot.com/2009/06/sort-checkednodes-treenodecollection-in.html),我從搜索中運行,直接在循環收集之前調用。它本質上是通過一個簡單的比較來檢查文本,並按順序返回一個新的集合。
從上面的鏈接:
private TreeNodeCollection SortTreeNode(TreeNodeCollection nodeList)
{
for (int i = 0; i < nodeList.Count-1; i++)
{
for (int j = i + 1; j < nodeList.Count; j++)
{
if (nodeList[i].Text.CompareTo(nodeList[j].Text)>0)
{
TreeNode temp = nodeList[i];
nodeList.RemoveAt(i);
nodeList.AddAt(i,nodeList[j-1]);
nodeList.RemoveAt(j);
nodeList.AddAt(j, temp);
}
}
}
return nodeList;
}
實施例調用代碼:
var tncInOrder = SortTreeNode(this.MyTreeView.CheckedNodes);
foreach (TreeNode node in tncInOrder)
{
//Iterate through the nodes in order
}
相關問題
- 1. treeview checked nodes
- 2. Treeview - Treenode - VB.Net - Not Displaying Nodes
- 3. Initializer list not order
- 4. time.sleep in python exceution order
- 5. SilverLight ListBoxDragDropTarget not changing order
- 6. Order in legend plots python
- 7. C++ mysql order by is not ordered
- 8. WP_Query order by meta_value_num not working
- 9. C#List Order Order
- 10. MySQL - IN中的ORDER BY值()
- 11. SQL-ORDER BY in IF-ELSE CLAUSE
- 12. Azure/U-SQL - ORDER BY in ROW_NUMBER()
- 13. JpaSpecificationExecutor JOIN + ORDER BY in Specification
- 14. Order select Object key in select Reactjs
- 15. Order Strings as Times in Dictionary
- 16. SELECT ... ORDER BY field IN(SELECT ...)not working on duplicate field
- 17. SQL order by in union所有查詢
- 18. mysql order-by original「where order」
- 19. Wordpress select order with order by
- 20. Cloud Spanner order without ORDER BY
- 21. ORDER BY with 2ndary indexes is not supported
- 22. C#List of Object not order by several objects down
- 23. mysql order by timestamp desc with limit range not working
- 24. sql order by not only with group by by only
- 25. Mysql組by by order by not working
- 26. Oracle sql order by not expected as working as expected?
- 27. Where in clause using order by得到結果
- 28. Tableau Calculated Field to Display Placement in Sort Order
- 29. Datagridview.SelectedCells order
- 30. ORDER BY條件