| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 654 人关注过本帖
标题:请教关于TreeView的使用
取消只看楼主 加入收藏
leely_lly
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-4-11
收藏
 问题点数:0 回复次数:0 
请教关于TreeView的使用

 这是我的代码,不知道以后的怎么做了,请大家赐教.谢谢!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;                  
using System.Windows.Forms;
using System.IO;


namespace Compress
{
public partial class FormFile : Form
{

public FormFile()
{
InitializeComponent();
}

private DirectoryInfo folder;


private void FormFile_Load(object sender, EventArgs e)
{
LoadTree();
}


private void LoadTree()
{
DirectoryInfo directory;

//clear the tree
//treeExplore.Nodes.Clear();


//Loop through the drive letter and find the available drive

foreach (string drive in Environment.GetLogicalDrives())
{
try
{
// get the directory information for this path
directory = new DirectoryInfo(drive);

//if the retrived directory is valid ,add it to the tree view
if (directory.Exists == true)
{
TreeNode newNode = new TreeNode(directory.FullName);
treeExplore.Nodes.Add(newNode);

//add the new node to the root level
GetSubDirectories(newNode);

}
}

catch
{
return;
}
}
}


private void GetSubDirectories(TreeNode parent)
{

DirectoryInfo directory;

try
{
//check if we have already scanned this folder

if (parent.Nodes.Count == 0)
{
directory = new DirectoryInfo(parent.FullPath);
foreach (DirectoryInfo dir in directory.GetDirectories())
{
TreeNode newNode = new TreeNode(dir.Name);
parent.Nodes.Add(newNode);

}
}

//Scan the frist level of sub folder to creat + or - sign
foreach (TreeNode node in parent.Nodes)
{

//if we have scanned this code before
if (node.Nodes.Count == 0)
{
//get the folder information for the special path
directory = new DirectoryInfo(node.FullPath);
foreach (DirectoryInfo dir in directory.GetDirectories())
{
//create a new node to add it to the tree

TreeNode newNode = new TreeNode(dir.Name);
node.Nodes.Add(newNode);
}
}
}
}

catch
{
return;
}
}

private void treeExplore_AfterSelect(object sender, TreeViewEventArgs e)
{
DirectoryInfo dirInfo = new DirectoryInfo(e.Node.FullPath);
listExplorer.Items.Clear();
if (dirInfo.Exists)
{
FileInfo[] fileInfo = dirInfo.GetFiles();
foreach (FileInfo info in fileInfo)
{
ListViewItem item = new ListViewItem();
item = listExplorer.Items.Add(info.Name);
item.SubItems.Add(info.LastAccessTime.ToString());
item.SubItems.Add(info.Length.ToString());
}
}
}

private void onMouseDown(object sender, MouseEventArgs e)
{
if (treeExplore.GetNodeAt(e.X, e.Y) != null)
{
compressMenuItem.Visible = true;
encryptMenuItem.Visible = true;
}
else
{
compressMenuItem.Visible=false;
encryptMenuItem.Visible=false;
}
}
本人是才学习,对于以上代码也是基本按照例子做的,,加载本地机子上的文件系统,我现在主要是想在listExplorer又点击文件,有弹出菜单,若是.zip的就解压缩,若是别的就实现压缩的功能,怎么编写代码,还有就是要用哪个命名空间,使用什么类呢?跪求解答!

搜索更多相关主题的帖子: using System TreeView public FormFile 
2007-04-11 15:54
快速回复:请教关于TreeView的使用
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.051100 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved