Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to add treeView1 controls to WinForm of C #

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to add treeView1 controls to the WinForm of C#". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to add treeView1 controls to the WinForm of C#".

Use the tag attribute of TreeNode to place the encoding, and the Text attribute of TreeNode to place the name. The simplest example is as follows-- add two nodes first, and then handle the AfterSelect event:

Summary description of using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; namespace testtree {/ Form1. / public class Form1: System.Windows.Forms.Form {private System.Windows.Forms.TreeView treeView1; / required designer variables. / private System.ComponentModel.Container components = null; public Form1 () {/ Windows forms designer support required / / InitializeComponent (); / TODO: add any constructor code / / TreeNode tn = new TreeNode () after the InitializeComponent call; tn.Tag = "1001"; tn.Text = "hello"; TreeNode tn2 = new TreeNode (); tn2.Tag = "1002" Tn2.Text = "ok"; tn.Nodes.Add (tn2); treeView1.Nodes.Add (tn);} / Clean up all resources in use. / / protected override void Dispose (bool disposing) {if (disposing) {if (components! = null) {components.Dispose ();}} base.Dispose (disposing);} # the code generated by the region Windows forms designer supports the required methods-do not modify the contents of this method using a code editor. / private void InitializeComponent () {this.treeView1 = new System.Windows.Forms.TreeView (); this.SuspendLayout (); / treeView1 Control / / this.treeView1.ImageIndex =-1; this.treeView1.Location = new System.Drawing.Point (16,8); this.treeView1.Name = "treeView1"; this.treeView1.SelectedImageIndex =-1; this.treeView1.TabIndex = 0; this.treeView1.AfterSelect + = new System.Windows.Forms.TreeViewEventHandler (this.treeView1_AfterSelect) / Form1 / / this.AutoScaleBaseSize = new System.Drawing.Size (6,14); this.ClientSize = new System.Drawing.Size (292266); this.Controls.Add (this.treeView1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout (false);} # endregion / main entry point of the application. / / [STAThread] static void Main () {Application.Run (new Form1 ());} private void treeView1_AfterSelect (object sender, System.Windows.Forms.TreeViewEventArgs e) {string s = treeView1.SelectedNode.Tag.ToString (); string S2 = treeView1.SelectedNode.Text.ToString () } Thank you for your reading, the above is the content of "how to add treeView1 controls to the WinForm of C#". After the study of this article, I believe you have a deeper understanding of the problem of how to add treeView1 controls to the WinForm of C#, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report