Soft IE control Treeview

Source: Internet
Author: User
ArticleDirectory
    • Node relationships and references to relative nodes
    • Adding node objects to the nodes collection
Download Treeview

Csdn Treeview topic discussion: http://search.csdn.net/Expert/topic/1525/1525202.xml? Temp =. 9699365.

Download Treeview: (source code available for compilation)

Http://msdn.microsoft.com/archive/en-us/samples/internet/asp_dot_net_servercontrols/webcontrols/default.asp

MSI file:

Http://www.microsoft.com/china/msdn/archives/library/dnaspp/html/aspnet-usingtreeviewiewebcontrol.asp

User blog: http://blog.csdn.net/xuandhu/archive/2005/04/18/352182.aspx

About Treeview webcontrol

Http://www.microsoft.com/china/msdn/archives/library/workshop/webcontrols/overview/treeview.asp

Using the Treeview Control

See also

The Treeview control is designed to display data that is hierarchical in nature, such as organization trees, the entries in an index, the files and directories on a disk.

Figure 2.40 typical Treeview

Possible Uses
    • To create an organization tree that can be manipulated by the user.

    • To create a tree that shows at least two or more levels of a database.
Setting Node object properties

A "Tree" is comprised of cascading branches of "nodes," and each node typically consists of an image (set with the Image property) and a label (set with the text property ). images for the nodes are supplied by an imagelist control associated with the Treeview control. for more information on using the imagelist control with other controls, see "using the imagelist control."

A node can be expanded or collapsed, depending on whether or not the node has child nodes-nodes which descend from it. at the topmost level are "root" nodes, and each root node can have any number of child nodes. the total number of nodes is not limited (cannot by machine constraints ). figure 2.41 shows a tree with two root nodes; "root 1" has three child nodes, and "child 3" has a child node itself. "Root 2" has child nodes, as indicated by the "+" sign, but is unexpanded.

Figure 2.41 root and Child Nodes

Each node in a tree is actually a programmable Node object, which belongs to the nodes collection. as in other collections, each member of the collection has a unique index and key property which allows you to access the properties of the node. for example, the code below uses the index of a particle node ("7") to set the image and text properties:

Tvwmytree. nodes (7). Image = "closed" tvwmytree. nodes (7). Text = "IEEE"

However, if a unique key, for example "7 id" had been assigned to the node, the same code cocould be written as follows:

 
Tvwmytree. nodes ("7 id"). Image = "closed" tvwmytree. nodes ("7 id"). Text = "IEEE"
Node relationships and references to relative nodes

Each node can be either a child or a parent, depending on its relationship to other nodes. the Node object features several properties which return various kinds of information about children or parent nodes. for example, the following code uses the children property to return the number of children-if any-a node has:

 
Msgbox tvwmytree. nodes (10). Children

However, some of the properties do not return information, as the children property does, but instead returnReferenceTo another Node object. for example, the Parent property returns a reference to the parent of any participant node (as long as the node is not a root node ). with this reference, you can manipulate the parent node by invoking any methods, or setting properties, that apply to node objects. for example, the code below returns the text and index properties of a parent node:

 
Msgbox tvwmytree. nodes (10). Parent. textmsgbox tvwmytree. nodes (10). Parent. Index

TipUse the set statement with an object variable of Type node to manipulate references to other node objects. for example, the code below sets a Node object variable to the reference returned by the parent property. the Code then uses the object variable to return properties of the relative node:

Dim tempnode as node 'descare object variable. 'set object variable to returned reference. set tempnode = tvwmytree. nodes (10 ). parent msgbox tempnode. text 'returns parent' s text. msgbox tempnode. index 'returns parent' s index.
Adding node objects to the nodes collection

To add a node to the tree, use the add method (nodes collection). This method has des two arguments,RelativeAndRelationship, Which can determine where the node will be added. The first argumentRelativeNames a node; the second argumentRelationshipSpecifies the relationship between the new node and the node named inRelative.

For example, the following code adds a node named "11 node" as a child of another node named "7 node. "the intrinsic constant tvwchild specifies that the new node is a child of the node named in the previous argument. the third argument assigns the key property to the new node.

Tvwmytree. nodes. Add "7 node", tvwchild, "11 node"

Other possible relationships include:

Constant Value Description
Tvwlast 1 The node is placed after all other nodes at the same level of the node named inRelative.
Tvwnext 2 The node is placed after the node named inRelative.
Tvwprevious 3 The node is placed before the node named inRelative.
Tvwchild 4 The node becomes a child node of the node named inRelative.

For example, suppose there were three existing nodes, and you wished to place a fourth node between the second and the third nodes, the Code wowould be:

 
'Assuming the second node's key value is "2 node". tvwmytree. nodes. Add "2 node", tvwnext

Other arguments of the add method areKey,Text, AndImage.Using these arguments, you can assign the key, text, and image properties as the Node object is created.

For more informationFor more information about the nodes collection's add method see "add method" by typing "add Method" in the index search and clicking "add method (nodes collection )."

A second way of adding nodes is to declare an object variable of Type node, and then use the set statement with the add method. the Set statement sets the object variable to the new node. you can then use the object variable to set the node's properties, as shown below:

 
Dim nodx as nodeset nodx = tvwmytree. nodes. add ("10 node", tvwchild) nodx. key = "11 node" nodx. TEXT = "IEEE" nodx. image = "closed"

TipUsing the set statement with the add method makes reading and debugging your code easier. However, using the add method and its arguments to add nodes creates faster code.

Treeview class

Displays a hierarchical collection of labeled items, each represented by a treenode.

For a list of all members of this type, see Treeview members.

System. Object
System. externalbyrefobject
System. componentmodel. Component
System. Windows. Forms. Control
System. Windows. Forms. Treeview

 
[Visual Basic]Public class Treeview inherits Control[C #]Public class Treeview: Control[C ++]Public _ GC class Treeview: Public Control[JScript]Public class Treeview extends control
Thread safety

Any public static (SharedIn Visual Basic) Members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

the nodes collection holds all the treenode objects that are assigned to the Treeview control. the Tree nodes in this collection are referred to as the root Tree nodes. any tree node that is subsequently added to a root tree node is referred to as a child node. because each treenode can contain a collection of other treenode objects, you might find it difficult to determine your location in the tree structure when you iterate through the collection. you can parse the treenode. fullpath string by using the pathseparator string value to determine where a treenode label begins and ends.

you can display images next to the tree nodes by assigning an imagelist object to the imagelist property, and referencing the index value of an image in the imagelist to assign that image . set the imageindex property to the index value of the image that you want to display when a tree node is not selected. likewise, set the selectedimageindex property to the index value of the image that you want to display when a tree node is selected. the images referenced by the imageindex and selectedimageindex property values are the default images displayed by all the Tree nodes that are assigned to the nodes collection. each tree node can override the default images by setting the treenode. imageindex and treenode. selectedimageindex properties.

Tree nodes can be expanded to display the next level of child Tree nodes. the user can expandTreenodeBy clicking the plus-sign (+) button, if one is displayed next toTreenode, Or you can expandTreenodeBy calling the treenode. Expand method. To expand all the child Tree node levels in the nodes collection, call the expandall method. You can collapse the childTreenodeLevel by calling the treenode. Collapse method, or the user can press the minus-sign (-) button, if one is displayed next toTreenode. You can also call the treenode. Toggle method to alternate between the expanded and collapsed States.

Tree nodes can optionally display check boxes. to display the check boxes, set the checkboxes property ofTreeviewToTrue. The checked property is setTrueFor Tree nodes that are in a checked state.

note setting the treenode. checked property from within the beforecheck or aftercheck event causes the event to be raised multiple times and can result in unexpected behavior. for example, you might set the checked property in the event handler when you are recursively updating the child nodes, so the user does not have to expand check each one individually. to prevent the event from being raised multiple times, add logic to your event handler that only executes your recursive Code if the action property of the treevieweventargs is not set to treeviewaction. unknown. for an example of how to do this, see the example section of the aftercheck or beforecheck events.

you can change the appearance of the Treeview control by setting some of its display and style properties. setting showplusminus to true displays a plus-sign or minus-sign button next to each treenode object that can be expanded or collapsed, respectively. setting the showrootlines property to true causes the Treeview to display lines that join all the root Tree nodes together. you can display lines that connect child Tree nodes to their root node by setting the showlines property to true . setting the hottracking property to true changes the appearance of the Tree node labels as the mouse pointer passes over them. when Hot-tracked, the tree node labels take on the appearance of a hyperlink.

NoteWhen settingCheckboxes, Scrollable,Imageindex, AndSelectedimageindexProperties at run time,TreeviewHandle is recreated (see control. recreatehandle) to update the control's appearance. This causes all Tree nodes to be collapsed, with the exception of the selectedTreenode.

Example

[Visual Basic, C #, C ++]The following example displays customer information inTreeviewControl. the root Tree nodes display Customer names, and the Child Tree nodes display the order numbers assigned to each customer. in this example, 1,000 customers are displayed with 15 orders each. the repainting ofTreeviewIs suppressed by using the beginupdate and endupdate methods, and a wait cursor is displayed whileTreeviewCreates and paints the treenode objects. This example assumes you haveCustomerObject that can hold a collectionOrderObjects. It also assumes that you have a cursor file namedMywait. curIn the application directory and that you have created an instance ofTreeviewControl on a form.

 [Visual Basic] 'Create a new arraylist to hold the customer objects. private customerarray as new arraylist () private sub fillmytreeview () 'add MERs to the arraylist of customer objects. dim X as integer for x = 0 to 999 mermerarray. add (new customer ("customer" + X. tostring () Next x 'add orders to each customer object in the arraylist. dim customer1 as customer for each customer1 in customerarray dim y as integer for Y = 0 to 14 customer1.customerorders. add (New Order ("order" + Y. tostring () Next y next customer1 'display a wait cursor while the treenodes are being created. cursor. current = new cursor ("mywait. cur ") 'ss RESS repainting the Treeview until all the objects have been created. treeview1.beginupdate () 'clear the Treeview each time the method is called. treeview1.nodes. clear () 'Add a root treenode for each customer object in the arraylist. dim customer2 as customer for each customer2 in customerarray treeview1.nodes. add (New treenode (customer2.customername) 'Add a child treenode for each order object in the current customer object. dim Order1 as order for each Order1 In customer2.customerorders treeview1.nodes (customerarray. indexof (customer2 )). nodes. add (_ new treenode (customer2.customername + ". "+ order1.orderid) Next Order1 next customer2 'reset the cursor to the default for all controls. cursor. current = system. windows. forms. cursors. default 'in in repainting the Treeview. treeview1.endupdate () end sub 'fillmytreeview [C #] // Create a new arraylist to hold the customer objects. private arraylist customerarray = new arraylist (); Private void fillmytreeview () {// Add MERs to the arraylist of customer objects. for (INT x = 0; x <1000; X ++) {customerarray. add (new customer ("customer" + X. tostring ();} // Add orders to each customer object in the arraylist. foreach (customer customer1 in customerarray) {for (INT y = 0; y <15; y ++) {customer1.customerorders. add (New Order ("order" + Y. tostring (); }}// display a wait cursor while the treenodes are being created. cursor. current = new cursor ("mywait. cur "); // suppress repainting the Treeview until all the objects have been created. treeview1.beginupdate (); // clear the Treeview each time the method is called. treeview1.nodes. clear (); // Add a root treenode for each customer object in the arraylist. foreach (customer customer2 in customerarray) {treeview1.nodes. add (New treenode (customer2.customername); // Add a child treenode for each order object in the current customer object. foreach (Order Order1 In customer2.customerorders) {treeview1.nodes [customerarray. indexof (customer2)]. nodes. add (New treenode (customer2.customername + ". "+ order1.orderid) ;}// reset the cursor to the default for all controls. cursor. current = cursors. default; // begin repainting the Treeview. treeview1.endupdate ();}[C ++] Void fillmytreeview () {// Add MERs to the arraylist of customer objects. for (INT x = 0; x <1000; X ++) {customerarray-> Add (new customer (string: Concat (S "customer ", _ box (X);} // Add orders to each customer object in the arraylist. ienumerator * myenum = customerarray-> getenumerator (); While (myenum-> movenext () {customer * customer1 = _ try_cast
 
  
(Myenum-> current); For (INT y = 0; y <15; y ++) {customer1-> customerorders-> Add (New Order (string :: concat (S "order", _ box (y) ;}// display a wait cursor while the treenodes are being created. cursor: Current = new system: Windows: forms: cursor (S "mywait. cur "); // suppress repainting the Treeview until all the objects have been created. treeview1-> beginupdate (); // clear the Treeview each time the method is called. treeview1-> nodes-> clear (); // Add a root treenode for each customer object in the arraylist. while (myenum-> movenext () {customer * customer2 = _ try_cast
  
   
    
(Myenum-> current); treeview1-> nodes-> Add (New treenode (customer2-> customername )); // Add a child treenode for each order object in the current customer object. ienumerator * myenum = customer2-> customerorders-> getenumerator (); While (myenum-> movenext () {Order * Order1 = _ try_cast

    
     
(Myenum-> current); treeview1-> nodes-> item [customerarray-> indexof (customer2)]-> nodes-> Add (New treenode (string :: concat (customer2-> customername, s ". ", Order1-> orderid) ;}// reset the cursor to the default for all controls. cursor: Current = cursors: default; // begin repainting the Treeview. treeview1-> endupdate ();}

    

    
  
 

[JScript]No example is available for JScript. To view a Visual Basic, C #, or C ++ example, click the Language Filter button in the upper-left corner of the page.

Requirements

Namespace:System. Windows. Forms

Platforms:Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family,. NET Compact framework

Assembly:System. Windows. Forms (in system. Windows. Forms. dll)

Implementation of the tree (netizen boytomato (who loves a girl named Ying !) )
Http://community.csdn.net/Expert/topic/4017/4017253.xml? Temp =. 1536829.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.