TreeView

xiaoxiao2021-03-06  40

1. Use preliminary (1) Download address http://msdn.microsoft.com/downloads/samples/internet/default.asp?url=/downloads/samples/internet/WebControls/default.asp (2) Do not display tree type Problem First: Download the package automatically installed and manually installs 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) @ 节 Node: 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) 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 for the currently selected node to be deleted, tmpNd3 as its parent node NdSel = Treepaybasic.GetNodeFromIndex (Treepaybasic .SelectedNodeIndex) 'deposits the cut node into session session ("Node") = ndsel if (TreePayBasic.SelectedNodeIndex <> "0") Tmpnd3 = 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's parent ndsel = treybasic.getnodefromindex (TreePaybasic.selectedNodeIndex) TMPND3 = session ("node") ndsel.nodes.add (TMPND3) 2. Recutorization of the algorithm and database design of recursive spanning trees (1) The programming method of the program call itself is called 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 NodeID, ParentID, NodeName, Address, and other fields (used to represent nodes, parent node ID, node name, link address), others The property is determined according to the 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 designated as follows: (Simplified model, actually useful to be complex) Primary key attribute name type length can be expressed in nodeid INT 6 No Node ID ParentID INT 6 No Parent Node ID NodeName Char 50 No Node Name Address 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) Nextend Sub ---------------- Call recursive function ------------ ------ CreateReaderDataSet () inittree (TreePaybasic.Nodes, 999) ----------------- Generate Data Set ------------- ------ 'Generate the function private sub createReaderDataSet ()' Connects at runtime and sets the connection properties myconn = new system.data.oledb.oledbconnection ("provider = msdara.1; data source = oracle9; User ID = user; password = ****; ") Sets selectcommand command myadapter.selectcommand = new system.data.oledb.oledbcommand (" Select * from treenode ", myconn) fill data set myadapter.fill (MySet, "TREENODE") End Sub .Net platform Web tree structure program Design My last article "Application of tree structure in development" is mainly implemented under Windows Form, below is the implementation under Web Form.

Database design First, we create a table TBTree in SQL Server 2000, the structure is designed as follows: Column name Data Type Description Leister Primary Key IDINT Node No. 4 is ParentIDint Parent Node No. 4 Contextnvarchar We want to display Node content 50 in SQL Server 2000 Script of China Construction Table: Create Table [DBO]. [TBTree] ([Id] [INT] Identity (1, 1) Not Null, [Context] [NVARCHAR] (50) Collate Chinese_PRC_CI_AS NULL, [ParentID] [INT] NULL) ON [PRIMARY] Add the following records in the table: Set Identity_Insert Tbtree On Insert Tbtree (ID, Context, Parentid) Values ​​(1, 'China', 0) Insert Tbtree (ID, Context, Parentid) Values ​​(2, ' Beijing ', 1) INSERT TBTREE (ID, Context, Parentid) Values ​​(3,' Tianjin ', 1) Insert TBTree (ID, Context, Parentid) Values ​​(4,' Hebei Province ", 1) Insert Tbtree (id, context , ParentID) Values ​​(5, 'Guangdong ", 1) INSERT TBTREE (ID, Context, Parentid) Values ​​(6,' Guangzhou ', 5) Insert Tbtree (ID, Context, Parentid) VALUES (7,' Sichuan" , 1) Insert Tbtree (ID, Context, Parentid) Values ​​(8, 'Chengdu', 7) Insert Tbtree (ID, Context, Parentid) Values ​​(9, 'Shenzhen', 5) Insert TBTree (ID, Context, ParentID) Values ​​(10, 'Shijiazhuang', 4) INSERT TBTREE (ID, Context, Parentid) Values ​​(11, 'Liaoning Province', 1) Insert T Btree (ID, Context, Parentid) Values ​​(12, 'Dalian', 11) Insert Tbtree (ID, Context, Parentid) Values ​​(13, Shanghai ', 1) Insert Tbtree (ID, Context, Parentid) VALUES (14, 'Tianhe Software Park', 6) INSERT TBTREE (ID, Context, Parentid) Values ​​(15, 'Shantou', 5) Set Identity_Insert Tbtree Off http://www.microsoft.com/china/community/columns/lihonggen/image /1-1.jpg Download TreeView control address http://msdn.microsoft.com/downloads/samples/internet/WebControls/default.asp After installation, pass the "Custom Toolbox" -> ". Net Framework component "Add TreeView to the toolbox. Create a new project, select the Visual Basic.Net Engineering ASP.NET web application, drag a TreeView control on the page.

Html page: <% @ Register TagPrefix = "iewc" Namespace = "Microsoft.Web.UI.WebControls" Assembly = "Microsoft.Web.UI.WebControls, Version = 1.0.2.226, Culture = neutral, PublicKeyToken = 31bf3856ad364e35"%> <% @ Page language = "vb" autoeventwireup = "false" codebehind = "Webform1.aspx.vb" inherits = "Tree.Webform1"%> http://schemas.microsoft.com/intellisense/ie5 ">

转载请注明原文地址:https://www.9cbs.com/read-52597.html

New Post(0)