Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to change a TreeList node position along with a corresponding record's position in the database

$
0
0

TreeList allows users to reorder nodes by dragging them with the mouse. If a node was moved from one parent to another, its position will be saved automatically, because it depends on the ParentID column value which is stored in the database. However, when nodes are reordered within the child collection, their position will be reset after the application is closed and opened again, or after reloading data.

To keep nodes positions, it is necessary to add additional column to the datasource to store the node index. In this situation, nodes positions can be restored after loading the data into the TreeList. This task can be accomplished by iterating all the nodes and updating the node index via the TreeList.SetNodeIndex method.

[C#]
voidUpdateNodesPositions(TreeListNodesnodes){List<TreeListNode>ns=newList<TreeListNode>();foreach(TreeListNodeninnodes)ns.Add(n);foreach(TreeListNodeninns){UpdateNodesPositions(n.Nodes);n.TreeList.SetNodeIndex(n,Convert.ToInt32(n.GetValue("Order")));}}
[VB.NET]
PrivateSub UpdateNodesPositions(ByVal nodes As TreeListNodes)Dim ns AsNew List(Of TreeListNode)()ForEach n As TreeListNode In nodes ns.Add(n)Next nForEach n As TreeListNode In ns UpdateNodesPositions(n.Nodes) n.TreeList.SetNodeIndex(n, Convert.ToInt32(n.GetValue("Order")))Next nEndSub


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>