用各个试试:
private void FillNodes(string path)
{
if(!Directory.Exists(path)){ MessageBox.Show("文件夹不存在。"); return; } string[] dirs = Directory.GetDirectories(path); string[] fs = Directory.GetFiles(path); foreach(string d in dirs)
{
try { this.treeView1.Nodes.Add(d); this.FillNodes(d); }
catch {}
Application.DoEvents();
}
foreach(string s in fs)
{
try{ this.treeView1.Nodes.Add(s); }
catch{}
Application.DoEvents();
}
}
private void FillNodes(string path)
{
if(!Directory.Exists(path)){ MessageBox.Show("文件夹不存在。"); return; } string[] dirs = Directory.GetDirectories(path); string[] fs = Directory.GetFiles(path); foreach(string d in dirs)
{
try { this.treeView1.Nodes.Add(d); this.FillNodes(d); }
catch {}
Application.DoEvents();
}
foreach(string s in fs)
{
try{ this.treeView1.Nodes.Add(s); }
catch{}
Application.DoEvents();
}
}
解决方案 »
- 编译器错误消息: CS0016: 未能写入输出文件“c:\Windows\Microsoft.NET\Framework\v2.0.50727\Tempor..
- Atom N280(270)上可以安装使用vs.net和sql吗
- dataset里的两个表怎么join成一个表呀
- C#想做计算器出现的问题
- winform下的 button checkonclick问题
- MDI窗体传值问题
- 一个复杂的问题,高手进
- 急求这个问题怎么解决MSI ERROR:directory....
- 关于textbox读取button的text的内容的问题
- Programming Windows With C#
- 既然C#Web应用程序.aspx中不能使用拆分窗体,那么......??
- 那位有有关treeview的程序,100分求购.
{
string dir = this.comboBox.Text;
string[] dirs=null; this.treeView.Nodes.Clear(); try
{
dirs = Directory.GetDirectories(@dir, "*");
}
catch(Exception)
{
MessageBox.Show("无法打开!!!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
} this.treeView.Nodes.Add(this.comboBox.Text);
EnumDrives(this.treeView.Nodes[0],this.treeView,this.comboBox,this.listBox);
}private void comboBox_SelectedIndexChanged(object sender, System.EventArgs e)
{
string dir = this.comboBox.Text;
string[] dirs=null; this.treeView.Nodes.Clear(); try
{
dirs = Directory.GetDirectories(@dir, "*");
}
catch(Exception)
{
MessageBox.Show("无法打开!!!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
return;
} this.treeView.Nodes.Add(this.comboBox.Text);
EnumDrives(this.treeView.Nodes[0],this.treeView,this.comboBox,this.listBox);
}
private void treeView_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
if(e.Node.Text.ToString()!=this.comboBox.Text)
EnumDirectories(e.Node,this.treeView,this.comboBox,this.listBox);//显示子目录的内容
else
EnumDrives(e.Node,this.treeView,this.comboBox,this.listBox);//显示根目录的内容
}public void EnumDrives(TreeNode ParentNode,System.Windows.Forms.TreeView treeView,System.Windows.Forms.ComboBox comboBox,System.Windows.Forms.ListBox listBox)
{
string errorStr = null;
treeView.SelectedNode=ParentNode;
if(ParentNode.Nodes.Count==0)
{
try
{
foreach(string directory in Directory.GetDirectories(comboBox.Text))
{
treeView.SelectedNode=ParentNode;
TreeNode TempNode=new TreeNode();
TempNode.Text=directory.Substring(directory.LastIndexOf(@"\")+1);
TempNode.Tag=directory;
TempNode.ImageIndex=0;
TempNode.SelectedImageIndex=11;
treeView.SelectedNode.Nodes.Add(TempNode);
treeView.SelectedNode.Nodes[treeView.SelectedNode.Nodes.Count-1].EnsureVisible();
}
}
catch(Exception ex)
{
errorStr = ex.ToString();
MessageBox.Show(ex.Message,"错误", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
}
if(errorStr!=null)
return; listBox.Items.Clear();
foreach(string directory in Directory.GetFiles(comboBox.Text,"*"))
{
listBox.Items.Add(directory.Substring(directory.LastIndexOf(@"\")+1));
}
}