C #-Tree View implementation and TreeView attributes --- ShinePans

Source: Internet
Author: User

Tree View TreeView attributes and Methods




Attribute Description
Nodes Obtains the set of Tree nodes allocated to the Tree View control.
PathSeparator Obtains or sets the delimiter string used by the tree node path.
SelesctedNode Obtains or sets the index value of the image list used when the tree node is selected.
ShowNodeToolTips Gets or sets a value to indicate whether the Tree nodes in a tree chart are sorted.
VisibleCount Obtain the total number of completely visible Tree nodes of the Tree View control.
CollapseAll Collapse all Tree nodes
ExpandAll Expand All Tree nodes
GetNodeAt Retrieve the Tree nodes at the specified position
GetNodeCount Retrieve the number of Tree nodes allocated to the Tree View Control
............................ ........................................ ........................................ ........................................ ........................................ ..



Event Description
AfterCheck After the tree node check box is selected
AfterCollapse After the tree node check box is selected
AfterExpand Occurs after the tree node is expanded
AfterSelect Occurs after the tree node is selected
NodeMouseClick This occurs when you click TreeView with the mouse.
NodeMouseDoubleClick This occurs when you double-click TreeNode with the mouse.

Form1.cs

Using System; using System. collections. generic; using System. componentModel; using System. data; using System. drawing; using System. linq; using System. text; using System. windows. forms; namespace TreeViewTest {public partial class Form1: Form {public Form1 () {InitializeComponent ();} private void Form1_Load (object sender, EventArgs e) {treeView1.ContextMenuStrip = contextMenuStrip1; // set TreeNode TopNode = treeView1.Nodes In the shortcut menu of the tree space. add (""); // create the first top-level node // create four basic nodes, indicating the four big branches TreeNode ParentNode1 = new TreeNode (" "); treeNode ParentNode2 = new TreeNode ("friend"); TreeNode ParentNode3 = new TreeNode ("instructor"); TreeNode ParentNode4 = new TreeNode ("Classmate "); // Add four basic nodes to top-level nodes. nodes. add (ParentNode1); TopNode. nodes. add (ParentNode2); TopNode. nodes. add (ParentNode3); TopNode. nodes. add (ParentNode4); // create six subnodes, indicating the six small branches TreeNode ChildNode1 = new TreeNode ("ShinePans "); treeNode ChildNode2 = new TreeNode ("dad"); TreeNode ChildNode3 = new TreeNode ("mom"); TreeNode ChildNode4 = new TreeNode ("xuzhengmao "); treeNode ChildNode5 = new TreeNode ("qinming"); TreeNode ChildNode6 = new TreeNode ("zhangyihui"); TreeNode ChildNode7 = new TreeNode ("xuzhengmao "); treeNode ChildNode8 = new TreeNode ("zhangyihui"); ParentNode1.Nodes. add (ChildNode1); ParentNode1.Nodes. add (ChildNode2); ParentNode1.Nodes. add (ChildNode3); ParentNode4.Nodes. add (ChildNode4); ParentNode3.Nodes. add (ChildNode5); ParentNode4.Nodes. add (ChildNode6); ParentNode2.Nodes. add (ChildNode7); ParentNode2.Nodes. add (ChildNode8);} private void treeView1_AfterSelect (object sender, TreeViewEventArgs e) {label1.Text = "selected Department:" + e. node. text;} private void expand all ToolStripMenuItem_Click (object sender, EventArgs e) {treeView1.ExpandAll ();} private void collapse all ToolStripMenuItem_Click (object sender, EventArgs e) {treeView1.CollapseAll ();}}}


Program. cs


Using System; using System. Collections. Generic; using System. Linq; using System. Windows. Forms; namespace TreeViewTest {static class Program {////// Main entry point of the application. ///[STAThread] static void Main () {Application. EnableVisualStyles (); Application. SetCompatibleTextRenderingDefault (false); Application. Run (new Form1 (); // Tree View }}}


Form1 Design


Namespace TreeViewTest {partial class Form1 {////// Required designer variables. ///Private System. ComponentModel. IContainer components = null ;////// Clear all resources in use. //////If the managed resources should be released, the value is true; otherwise, the value is false.Protected override void Dispose (bool disposing) {if (disposing & (components! = Null) {components. Dispose ();} base. Dispose (disposing);} # code generated by region Windows Form Designer ////// The designer supports the required methods-do not // use the code editor to modify the content of this method. ///Private void InitializeComponent () {this. components = new System. componentModel. container (); this. treeView1 = new System. windows. forms. treeView (); this. contextMenuStrip1 = new System. windows. forms. contextMenuStrip (this. components); this. label1 = new System. windows. forms. label (); this. expand All ToolStripMenuItem = new System. windows. forms. toolStripMenuItem (); this. collapse all ToolStripMenuItem = new System. windows. forms. toolStripMenuItem (); this. contextMenuStrip1.SuspendLayout (); this. suspendLayout (); // treeView1 // this. treeView1.Location = new System. drawing. point (5, 7); this. treeView1.Name = "treeView1"; this. treeView1.Size = new System. drawing. size (247,294); this. treeView1.TabIndex = 0; this. treeView1.AfterSelect + = new System. windows. forms. treeViewEventHandler (this. treeviewmediaafterselect); // contextMenuStrip1 // this. contextMenuStrip1.Items. addRange (new System. windows. forms. toolStripItem [] {this. expand All ToolStripMenuItem, this. collapse all ToolStripMenuItem}); this. contextMenuStrip1.Name = "contextMenuStrip1"; this. contextMenuStrip1.Size = new System. drawing. size (153, 70); // label1 // this. label1.AutoSize = true; this. label1.Location = new System. drawing. points (11,320); this. label1.Name = "label1"; this. label1.Size = new System. drawing. size (0, 12); this. label1.TabIndex = 2; // expand all ToolStripMenuItem // this. expand ToolStripMenuItem. name = "Expand All ToolStripMenuItem"; this. expand ToolStripMenuItem. size = new System. drawing. size (152, 22); this. expand ToolStripMenuItem. text = "Expand All"; this. expand ToolStripMenuItem. click + = new System. eventHandler (this. expand All ToolStripMenuItem_Click); // fold all ToolStripMenuItem // this. collapse all ToolStripMenuItem. name = "hide all ToolStripMenuItem"; this. collapse all ToolStripMenuItem. size = new System. drawing. size (152, 22); this. collapse all ToolStripMenuItem. text = "hide all"; this. collapse all ToolStripMenuItem. click + = new System. eventHandler (this. collapse all ToolStripMenuItem_Click); // Form1 // this. autoScaleDimensions = new System. drawing. sizeF (6F, 12F); this. autoScaleMode = System. windows. forms. autoScaleMode. font; this. clientSize = new System. drawing. size (260,361); this. controls. add (this. label1); this. controls. add (this. treeView1); this. name = "Form1"; this. text = "Tree View"; this. load + = new System. eventHandler (this. form1_Load); this. contextMenuStrip1.ResumeLayout (false); this. resumeLayout (false); this. extends mlayout () ;}# endregion private System. windows. forms. treeView treeView1; private System. windows. forms. contextMenuStrip contextMenuStrip1; private System. windows. forms. label label1; private System. windows. forms. toolStripMenuItem expand all ToolStripMenuItem; private System. windows. forms. toolStripMenuItem collapse all ToolStripMenuItem ;}}


Related Article

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.