Winform中关于treeView控件的做法,大家都比较了解。本文将谈到的是treeView1控件的增加过程,希望对广大开发人员有所帮助。

创新互联公司长期为近千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为遂溪企业提供专业的成都网站制作、成都网站建设、外贸营销网站建设,遂溪网站改版等技术服务。拥有10年丰富建站经验和众多成功案例,为您定制开发。
使用TreeNode的tag属性放置编码,TreeNode的Text属性放置名称,最简单的示例如下——先添加两个节点,然后处理AfterSelect事件:
- 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;
 - ///
 - /// 必需的设计器变量。
 - ///
 - private System.ComponentModel.Container components = null;
 - public Form1()
 - {
 - //
 - // Windows窗体设计器支持所必需的
 - //
 - InitializeComponent();
 - //
 - // TODO:在InitializeComponent调用后添加任何构造函数代码
 - //
 - TreeNode tn = new TreeNode();
 - tn.Tag = "1001"; tn.Text = "hello";
 - TreeNode tn2 = new TreeNode();
 - tn2.Tag = "1002"; tn2.Text = "ok";
 - tn.Nodes.Add(tn2);
 - treeView1.Nodes.Add(tn);
 - }
 - ///
 - /// 清理所有正在使用的资源。
 - ///
 - protected override void Dispose( bool disposing )
 - {
 - if( disposing )
 - {
 - if (components != null)
 - {
 - components.Dispose();
 - }
 - }
 - base.Dispose( disposing );
 - }
 - #region Windows窗体设计器生成的代码
 - ///
 - ///设计器支持所需的方法-不要使用代码编辑器修改
 - /// 此方法的内容。
 - ///
 - private void InitializeComponent()
 - {
 - this.treeView1 = new System.Windows.Forms.TreeView(); this.SuspendLayout();
 - //
 - // treeView1控件
 - //
 - 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(292, 266); this.Controls.Add(this.treeView1); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false);
 - }
 - #endregion
 - ///
 - /// 应用程序的主入口点。
 - ///
 - [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();
 - }
 - }
 - }
 
关于C#的WinForm增加treeView1控件就总结到这里。
                文章题目:详解C#的WinForm增加treeView1控件
                
                标题来源:http://www.csdahua.cn/qtweb/news43/526593.html
            
网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 快上网