All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
PHP开发中接收复选框信息的方法_[PHP教程]
ASP.NET程序错误“HTTP1.0,500,Server,Error”的一个解决办法
《Effective,C#》之减少装箱和拆箱_.net资料_编程技术
PHP语言中的经典应用技巧_[PHP教程]
小结:几点提高php序运行效率的方法_php资料_编程技术
C#编程技巧:轻松实现对文件的操作_[Asp.Net教程]
Sql,server表面区域配置工具保服务_[SQL,Server教程]
visual c++控件使用实例
Access升迁SQL,Server_[SQL,Server教程]
动态网页制作PHP之看实例学正则表达式_php资料_编程技术
Reading number is top 10 pictures
From China fortress sora aoi2
Sora aoi mirror memorial classics2
Shandong jinan is about to dismantle a one hundred-year history of the building
Players in the eyes of a perfect love2
教你做读书笔记
再发两张抽象画
奇趣的世界记录1
30 beautiful school beauty1
牛奶和人奶哪个好?
So beauty, will let you spray blood3
Download software ranking
Kung fu panda - the secret of the teacher
C#与.NET技术平台实战演练
Macromedia Dreamweaver 8
卡丁车单机版
Unix video tutorial11
Boxer's Top ten classic battle1
Unix video tutorial10
I'm come from Beijing2
Unix video tutorial9
Kung.Fu.Panda.2
qq published in(发表于) 2014/7/11 9:18:19 Edit(编辑)
C#中TreeView控件应用实例

C#中TreeView控件应用实例

C#中TreeView控件应用实例

TreeView控件

功能

TreeView控件可为用户显示节点层次结构,和在Windows操作系统的资源管理器的左窗格中显示文件和文件夹一样。树视图中的各个节点都可以包含其他节点。用户可以按展开或折叠的方式显示父节点或包含子节点的节点。另外,通过将树视图的CheckBoxes属性设置为True,可以在节点旁边显示复选框,用户可以通过将节点的Checked属性设置为True或False来选中或清除节点。图1为TreeView控件。



图1 TreeView控件

2.属性

TreeView控件常用属性及说明如表1所示。



表1 TreeView控件常用属性及说明

下面详细介绍Nodes属性,该属性用于设置TreeView控件中的所有节点。

语法:

public TreeNodeCollection Nodes { get; }

属性值:TreeNodeCollection,表示分配给树视图控件的树节点。

示例

使用Nodes属性向TreeView控件中添加节点

本示例使用Nodes属性向TreeView控件中添加节点,运行结果如图2所示。



图2 使用Nodes属性向TreeView控件中添加节点

程序主要代码如下:

SqlConnection con = new SqlConnection("server=ZHYzhy;uid=sa;pwd=;database=student");

con.Open();

SqlCommand com = new SqlCommand("select * from student", con);

SqlDataReader dr = com.ExecuteReader();

TreeNode newNode1 = TvStunt.Nodes.Add("学生信息");

while (dr.Read())

{

newNode1.Nodes.Add(dr[1].ToString());

}

dr.Close();

con.Close();

完整程序代码如下:

★★★★★主程序文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.Windows.Forms;

namespace _8_08

{

static class Program

{

///



/// 应用程序的主入口点。

///


[STAThread]

static void Main()

{

Application.EnableVisualStyles();

Application.SetCompatibleTextRenderingDefault(false);

Application.Run(new frmTrerView());

}

}

}

★★★★★frmTrerView窗体设计文件完整程序代码★★★★★

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace _8_08

{

public partial class frmTrerView : Form

{

public frmTrerView()

{

InitializeComponent();

}

private void bntAdd_Click(object sender, EventArgs e)

{

// Removes currently selected node, or root if nothing

//// is selected.

//treeView1.Nodes.Remove(treeView1.SelectedNode);

//// Clears all nodes.

//TreeView1.Nodes.Clear();

//TreeNode newNode1 = new TreeNode("学生信息");

SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=;database=zhy");

con.Open();

SqlCommand com = new SqlCommand("select * from student", con);

SqlDataReader dr = com.ExecuteReader();

TreeNode newNode1 = TvStunt.Nodes.Add("学生信息");

while (dr.Read())

{

newNode1.Nodes.Add(dr[1].ToString());

}

dr.Close();

con.Close();

}

private void bntEsce_Click(object sender, EventArgs e)

{

Application.Exit();

}

private void bntImage_Click(object sender, EventArgs e)

{

}

private void TvStunt_AfterSelect(object sender, TreeViewEventArgs e)

{

}

private void frmTrerView_Load(object sender, EventArgs e)

{

}

}

}

★★★★★frmTrerView窗体代码文件完整程序代码★★★★★

namespace _8_08

{

partial class frmTrerView

{

///

/// 必需的设计器变量。

///


private System.ComponentModel.IContainer components = null;

///

/// 清理所有正在使用的资源。

///



添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.