internal void GenerateNewListOfNodesFromTreeViewControl(TreeNode CurrentNode, ref int nodeCount, ref List <Topic> generatedList) // the 2 ref parameters must be passed for recursion { // visits all the childrens of CurrentNode in the Treeview. // with the Modified Tree Traversal algorithm // add a new element for the List that we will save to the database Topic ct = ((Topic)CurrentNode.Tag); ct.LeftNodeNew = nodeCount++; // manages left node number generatedList.Add((Topic)CurrentNode.Tag); if (ct.Id == null || ct.Id == 0) { // if CurrentNode is a new node, then we create it in the database, // so that it will have its Id. It will be saved with correct data // in the following because new and old values will differ ct.Id = db.CreateNewTopic(ct); } int brotherNo = 1; foreach (TreeNode sonNode in CurrentNode.Nodes) { // calls passing the updated count and the list under construction GenerateNewListOfNodesFromTreeViewControl(sonNode, ref nodeCount, ref generatedList); ((Topic)sonNode.Tag).ParentNodeNew = ct.Id; ((Topic)sonNode.Tag).ChildNumberNew = brotherNo++; } // If brothers are finished saves data of itself and returns. // right node management ((Topic)CurrentNode.Tag).RightNodeNew = nodeCount++; }