I have recently made a program. Among them, TreeView is used. In the program, I use TreeView in the frame. And the TreeView has increased, deleted, modified, and traversed by TreeView. During use, there is a lot of problems. Now I will summarize the program, I hope to discuss with everyone. What is wrong, hopes to communicate with the masters. I also hope to have a little help to netizens who have just used TreeView. 1. Use preliminary (1) download address
http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/ASP_DOT_NET_SERVERCONTROLS/WebControls/default.asp (2) Do not display the tree problem First: download the package Automatically install and manually install two packages. To download the automatic installation package of about 650K. Second: TreeView requires the client browser version of IE5.5 and above, it is best to require client upgrade to IE6.0 (3) About Blinking AUTOPOSTBACK property to true, SELECTEDEXCHANGE can be executed. However, this is very powerful. Don't refresh, set the autopostback property to false. (4) Several properties and methods of commonly used properties and methods ~ INDEX get the tree node location in the tree node. ~ Nodes Get the tree node collection assigned to the tree view control. ~ Parent gets or sets the parent container for the control. ~ SelectedNode Gets or sets the tree node currently selected in the tree view control. ~ ExpandALL Expands all tree nodes. ~ Checked gets or sets a value to indicate if the tree node is selected. ~ Text Gets or sets the text displayed in the tree node tag. ~ Expand Expand the tree node. ~ CLEAR Clear Tree ~ Remove removes the current tree node from the tree view control. (5) Commonly used operations: increase, delete, modify, cut @ increase node: DIM TMPND3 AS New Microsoft.Web.ui.WebControls.treenode () Dim Ndsel As New Microsoft.Web.ui.WebControls.treenode ( ) 'NDSEL is the currently selected node, the new node will be its child node ndsel = treepaybasic.getnodeFromindex (TreePaybasic.selectedNodeIndex) tmpnd3.text = "Add Node" in the tree Add this new node ndsel.nodes.add (TMPND3) @ Delete Node:
DIM TMPND3 AS New Microsoft.Web.ui.WebControls.treenode () Dim Ndsel As New Microsoft.Web.ui.WebControls.treenode () 'NDSEL For the currently selected to delete nodes, TMPND3 is its parent ndsel = treybasic .GetNodeFromIndex (Treepaybasic.SelectedNodeIndex) If (Treepaybasic.SelectedNodeIndex <> "0") Then tmpNd3 = NdSel.Parent tmpNd3.Nodes.Remove (NdSel) Else Treepaybasic.Nodes.Clear () End If @ modify the node: Dim NdSel As New Microsoft.Web.UI.WebControls.TreeNode () NdSel = Treepaybasic.GetNodeFromIndex (Treepaybasic.SelectedNodeIndex) NdSel.Text = "aaa" @ cut cut and paste: Dim tmpNd3 As New Microsoft.Web.UI.WebControls.TreeNode ( Dim ndsel as new microsoft.Web.ui.WebControls.treenode () 'ndsel is the currently selected to delete nodes, TMPND3 is its parent ndsel = treePaybasic.getnodeFromindex (TreePaybasic.SelectedNodeIndex)' will cut the node Deposit Session Session ("Node") = ndsel if (TreePaybasic.SelectedNodeIndex <> "0") THENTMPND3 = ndsel.parent Tmpnd3.Nodes.Remove (ndsel) endiff Paste: Dim Tmpnd3 As New Microsoft.Web.ui. WebControls.treenode () Dim Ndsel As new Microsoft.Web.ui.WebControls.treenode () 'NDSEL is the parent node ndsel = treybasic.getnodefromindex ("node") ndsel.Nodes.Add (TMPND3) 2. Database design (TMPND3) ("Node") NDSEL.NODES.ADD (TMPND3) 2. Algorithm and database design (1) Recursive Description Program Calling itself a recursive (Recursion). In the generation of the tree and the traversal of the map, there are many of the hands. The classic algorithm is n! (See the step by N), it is a recursive method. The advantages of the recursive algorithm are simple and expandable. But the disadvantage is also obvious: inefficient. Because recursive is that the program continues to call itself, it is relatively large for the resource consumption of the system. As the node increases, the execution efficiency will become very low. In order to solve the problem with the laminar tree during the generation process, it is also to make the tree's scalability better. The generation of the tree uses a recursive method. Once the code of the spanning tree is written, the source code can be generated, generating an unlimited level of the tree. The structure of the tree is completely determined by the data in the database. (2) Database design
Create a database, design the tree graph information table Treetable, the property contains the NodeID, ParentID, NodeName, Address and other fields (used to represent the node ID, parent node ID, node name, link address), other attributes according to actual user needs And design. Node Nodename will display on the node of the tree control, the NodeID field saves the unique identification number of the node, and the ParentId represents the current node's parent ID number (for example, there are two nodes are the father and child relationship, the child's node's ParentID value is its parent node NodeID), the node number, the child, the parent, forms a "linked list", characterizes and records the hierarchy of the tree node. The table is specific to the following: (Simplified model, actual use to be complex) Primary key attribute name type Length vacancy property meaning is NodeID INT 6 No Parent Node ID NodeName Char 50 No Node NODNAME CHAR 80 can be linked Address Note: The link address is mainly used in: the environment used in the tree in the frame. The link can point to the address in other framepages or with different parameters. (3) Program code ------------ Remissive function ------------ 'Spanned Tree Function Private Sub INITTREE (byref nds as microsoft.web.ui.webControls .TreeNodeCollection, ByVal parentId as Integer) Dim dv as New DataView () Dim dvrow as DataRowView Dim tmpNode as Microsoft.Web.UI.WebControls.TreeNode 'intId numerical variable, whose role is to record the current record and the delivery ID, do The ParentID value DIM intid as integer DV.table = mySet.tables ("Paybasic") 'ParentID is passed by the additem function. The role of the following statement is to find the child collection of the current node. DV.rowfilter = "ParentID = '" & ParentID & "'" If the current node has children, traverse all children and call the recursive function. FOR Each DVROW IN DV TMPNODE = New Microsoft.Web.ui.WebControls.treenode () 'assigns values for each attribute for the current node. TmpNode.ID = DVROW ("NodeID") TmpNode.Text = DVROW ("NodeName") TmpNode.NaviGateURL = DVROW ("Address") intid = dvrow ("ParentID") 'Add a node nds.add (tmpnode)' call Recurrent function inittree (nds (nds.count - 1) .nodes, intid) Next End Sub