在学习的路上

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

窗体控件无非就是有treeview和listview,摆放由自己摆放
以下是代码

 1using System;
 2using System.Collections.Generic;
 3using System.ComponentModel;
 4using System.Data;
 5using System.Drawing;
 6using System.Text;
 7using System.IO;
 8using System.Windows.Forms;
 9
10namespace WindowsApplication1
11{
12    public partial class Form1 : Form
13    {
14        public Form1()
15        {
16            InitializeComponent();
17        }

18
19        string lj = @"G:\";
20        private void Form1_Load(object sender, EventArgs e)
21        {
22            treeView1 .Nodes.Clear ();
23            treeView1.Nodes.Add(lj, Path.GetFileNameWithoutExtension(lj));//添加第一个节点
24            treeView1.Nodes[0].SelectedImageIndex = 1;
25            DGWJJ(lj,treeView1 .Nodes[0]);
26            //treeView1.Nodes[0].Expand();
27            BLWJJ(lj);
28
29        }

30
31
32        private void BLWJJ(string lj)
33        {
34            listView1.Items.Clear();
35            foreach (string zwjj in Directory.GetDirectories(lj))
36            {
37                listView1.Items.Add(zwjj, Path.GetFileNameWithoutExtension(zwjj), 0);
38            }

39            foreach (string zwjj in Directory.GetFiles(lj))
40            {
41                listView1.Items.Add(zwjj, Path.GetFileName(zwjj), 2);
42            }

43
44        }

45
46        private void DGWJJ(string lj, TreeNode node)
47        {
48            foreach (string zlj in Directory.GetDirectories(lj))
49            {
50                
51                    TreeNode t1 = node.Nodes.Add(zlj, Path.GetFileNameWithoutExtension(zlj));
52                    t1.ImageIndex = 0;
53                    t1.SelectedImageIndex = 1;
54                    DGWJJ(zlj, t1);
55               
56            }

57        }

58
59        private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
60        {
61            BLWJJ(e.Node.Name);   
62        }

63
64        private void listView1_DoubleClick(object sender, EventArgs e)
65        {
66            string lslj = listView1.SelectedItems[0].Name;
67            BLWJJ(lslj  );
68
69            DG(lslj,treeView1.Nodes[0]  );
70
71
72        }

73
74        private void DG(string lj,TreeNode tn)
75        {
76            foreach (TreeNode tn1 in tn.Nodes)
77            {
78                if (tn1.Name == lj)
79                {
80                   //tn.Expand;
81                   tn1.Expand();
82                    // tn1.ExpandAll();
83                }
             
84
85                DG(lj, tn1);
86            }

87        }

88
89        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
90        {
91
92        }

93    }

94}
posted on 2008-07-04 21:22  曲家林  阅读(380)  评论(0编辑  收藏  举报