你需要看TreeNode Class
例子:
private void Form1_Load(object sender, EventArgs e)
{
//
// This is the first node in the view.
//
TreeNode treeNode = new TreeNode("Windows");
treeView1.Nodes.Add(treeNode);
//
// Another node following the first node.
//
treeNode = new TreeNode("Linux");
treeView1.Nodes.Add(treeNode);
//
// Create two child nodes and put them in an array.
// ... Add the third node, and specify these as its children.
//
TreeNode node2 = new TreeNode("C#");
TreeNode node3 = new TreeNode("VB.NET");
TreeNode[] array = new TreeNode[] { node2, node3 };
//
// Final node.
//
treeNode = new TreeNode("Dot Net Perls", array);
treeView1.Nodes.Add(treeNode);
}
虽然示例不是从DB 读取节点。您可以编写查询来获取节点。按照以下路径的步骤操作,它将引导您从头开始
Create a TreeView from a Database in Windows Forms and C#
示例来源:Tree View
要在节点上打开文件,请单击查看
public event TreeNodeMouseClickEventHandler NodeMouseClick
// If a node is double-clicked, open the file indicated by the TreeNode.
void treeView1_NodeMouseClick(object sender,
TreeNodeMouseClickEventArgs e)
{
try
{
System.Diagnostics.Process.Start(@"c:\" + e.Node.Text);//e.Node.Text contains fileName
}
// If the file is not found, handle the exception and inform the user.
catch (System.ComponentModel.Win32Exception)
{
MessageBox.Show("File not found.");
}