日期:2014-05-17 浏览次数:21131 次
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
SetupControls();
}
public void SetupControls()
{
string[] data =
{
"Flowmaster",
"Flowmaster\\network1",
"Flowmaster\\network2",
"Flowmaster\\project1",
"Flowmaster\\project1\\network3",
"Flowmaster\\project2",
"Flowmaster\\project2\\network4"
};
CreateTree(data);
}
public void CreateTree(string[] data)
{
string[] roots = data.Select(a => a.Split('\\')[0]).Distinct().ToArray();
foreach (string path in roots)
{
TreeNode root = new TreeNode();
root.Text = path;
root.Name = path;
CreateSubTree(data, root);
treeView1.Nodes.Add(root);
}
}
public void CreateSubTree(string[] data, TreeNode parent)
{
string[] childs =data.