TreeView control tree control fill VB and VS.NET C # source code

xiaoxiao2021-03-06  33

TreeView control tree control fill VB and VS.NET C # source code

February 23, 2005 09:25 Wednesday [DEV Development]

It is used to the tree structure, it seems that many foreign websites developers call Netscapte Per, which may be because the Netscapte browser is more fashionable, and it is indeed that it is the most attributable to use this dialog mode VB. It's more simple, VC is more trouble. Gossip less, www.shengfang.org tells the filler

Database: The simplest table SS field: ID / name / parent, represents ID, name, and parent ID, the highest layer is 0 casual 1 / W / 0 2 / E / 1 3 / R / 2 4 / t / 1 respectively www.shengfang.org represents four different nodes.

VB is very simple: cmd.CommandText = "select * from ss" rs.CursorLocation = adUseClientrs.Open cmd,, adOpenDynamic, adLockOptimistic 'ss.Nodes.ClearIf rs.RecordCount <> 0 Then rs.MoveFirstEnd IfWhwww.shengfang.orgile (rs.eof = false) set nodd = tv_group.nodes.add (, TVwlast, Str (RS! ID) "SSID", _ rs! name, 1) debug.print nodd.key rs.Movenextwend if rs.Recordcount <> 0 THEN RS.MOVEFIRSTEND IFWHILE (RS! PARENT <> 0) THEN SET TV_GROUP.NODES (STR (RS! ID) "SSID"). Parent = TV_Group.Nodes (Str _ Rs! Parent) "SSID") Else TV_Grouwww.shengfang.orgp.nodes (STR (RS! ID) "SSID"). SELECTED = true end if rs.movenextwend rsclose End Sub First get all records, Www.shengfang.org then populates all the records in the root directory of Tree Control TreeCtrl, then set the Parent property of all parent nodes Nodes to the previous key for the Parent field, so that simple orders are all filled Complete

Vs.net is different, the Parent property seems to be read-only, only recursive private void inittree () {tree.nodes.clear (); CLS_PHS_Node www.shengfang.orgclsnodep = new CLS_PHS_NODE ("ss"); / / Because TreeView's Node node property does not seem to be a key attribute, it can only inherit a class, expand a key clsnodep.key = "0"; tree.nodes.add (clsnodep); // define one Root node oledbdataadapter Da = new OLEDBDataAdapter ("Select * from ss;"; dataable dt = new dataable (); da.fill (dt); da.dispose (); fixtree (Tree.Nodes [0] .nodes , "0", DT);} // Plip the data of the database table in the root node under the root node private nodes, string parentkey, datatable table {foreach (DataRow Dr in Table.Rows) {ix (DR ["parent"]. TOSTRING () == Parentkey.toTSTRING ()) {CLS_PHS_NODE CLSNODE = New CLS_PHS_NODE (DR ["Name"]. TOSTRING (). Trim ()); clsnode.key = dr ["id "] .Tostring (). Trim (); clsnode.type = dr [" parent "]. Tostring (). Trim (); nodes.add (clsnode); FillTree (clsnode.www.shengfang.orgnodes, DR [" ID "]. TOSTRING (), TABLE);}}} Don't quite understand why the TreeView control of www.shengfang.org in vs.net saves the comments of Node The key attribute and the Parent property becomes read-only, but there is no way.

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

New Post(0)