class="article_content clearfix">
class="htmledit_views">
using System.IO;
using System.Management;
public class BindFiles
{
private TreeView class="tags" href="/tags/TREE.html" title=tree>treeView1;
public BindFiles(TreeView class="tags" href="/tags/TREE.html" title=tree>tree)
{
class="tags" href="/tags/TREE.html" title=tree>treeView1 = class="tags" href="/tags/TREE.html" title=tree>tree;
}
//绑定class="tags" href="/tags/TREE.html" title=tree>treeView
public void GetTreeNode()
{
this.class="tags" href="/tags/TREE.html" title=tree>treeView1.Nodes.Clear();
SelectQuery selectQuery = new SelectQuery("select * from win32_logicalclass="tags" href="/tags/DISK.html" title=disk>disk");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery);
int i = 0;
foreach (ManagementObject class="tags" href="/tags/DISK.html" title=disk>disk in searcher.Get())
{
if(class="tags" href="/tags/DISK.html" title=disk>disk["DriveType"].ToString() == "3")
{
TreeNode node = new TreeNode();
node.Text = class="tags" href="/tags/DISK.html" title=disk>disk["Name"].ToString();
node.Tag = class="tags" href="/tags/DISK.html" title=disk>disk["Name"].ToString()+"//";
node.ImageIndex = 0;
this.class="tags" href="/tags/TREE.html" title=tree>treeView1.Nodes.Add(node);
//开始不想加载子文件,完则将此句代码注释
InsertTree(class="tags" href="/tags/TREE.html" title=tree>treeView1.Nodes[i].Nodes, class="tags" href="/tags/DISK.html" title=disk>disk["Name"].ToString());
i ++;
}
}
}
/// <summary>
/// 填充class="tags" href="/tags/TREE.html" title=tree>treeView节点
/// </summary>
/// <param name="nodes">要填充节点的父节点的子节点集合</param>
/// <param name="dir">父节点所代表的路径</param>
public void InsertTree(TreeNodeCollection nodes, class="tags" href="/tags/STRING.html" title=string>string dir)
{
class="tags" href="/tags/STRING.html" title=string>string[] cats = new class="tags" href="/tags/STRING.html" title=string>string[0];
try { cats = Directory.GetDirectories(dir); }
catch { }
if(cats.Length>0)
{
foreach( class="tags" href="/tags/STRING.html" title=string>string cat in cats)
{
TreeNode node = new TreeNode();
node.Text = cat.Subclass="tags" href="/tags/STRING.html" title=string>string(cat.LastIndexOf("//")+1);
node.Tag = cat+"//";
node.ImageIndex = 1;
node.SelectedImageIndex = 2;
nodes.Add(node);
nodes[nodes.Count-1].EnsureVisible();
//不想一次性加载完所有子文件,则将此句代码注释
InsertTree(node.Nodes, cat);
}
}
}
}
using System.Management;
public class BindFiles
{
private TreeView class="tags" href="/tags/TREE.html" title=tree>treeView1;
public BindFiles(TreeView class="tags" href="/tags/TREE.html" title=tree>tree)
{
class="tags" href="/tags/TREE.html" title=tree>treeView1 = class="tags" href="/tags/TREE.html" title=tree>tree;
}
//绑定class="tags" href="/tags/TREE.html" title=tree>treeView
public void GetTreeNode()
{
this.class="tags" href="/tags/TREE.html" title=tree>treeView1.Nodes.Clear();
SelectQuery selectQuery = new SelectQuery("select * from win32_logicalclass="tags" href="/tags/DISK.html" title=disk>disk");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(selectQuery);
int i = 0;
foreach (ManagementObject class="tags" href="/tags/DISK.html" title=disk>disk in searcher.Get())
{
if(class="tags" href="/tags/DISK.html" title=disk>disk["DriveType"].ToString() == "3")
{
TreeNode node = new TreeNode();
node.Text = class="tags" href="/tags/DISK.html" title=disk>disk["Name"].ToString();
node.Tag = class="tags" href="/tags/DISK.html" title=disk>disk["Name"].ToString()+"//";
node.ImageIndex = 0;
this.class="tags" href="/tags/TREE.html" title=tree>treeView1.Nodes.Add(node);
//开始不想加载子文件,完则将此句代码注释
InsertTree(class="tags" href="/tags/TREE.html" title=tree>treeView1.Nodes[i].Nodes, class="tags" href="/tags/DISK.html" title=disk>disk["Name"].ToString());
i ++;
}
}
}
/// <summary>
/// 填充class="tags" href="/tags/TREE.html" title=tree>treeView节点
/// </summary>
/// <param name="nodes">要填充节点的父节点的子节点集合</param>
/// <param name="dir">父节点所代表的路径</param>
public void InsertTree(TreeNodeCollection nodes, class="tags" href="/tags/STRING.html" title=string>string dir)
{
class="tags" href="/tags/STRING.html" title=string>string[] cats = new class="tags" href="/tags/STRING.html" title=string>string[0];
try { cats = Directory.GetDirectories(dir); }
catch { }
if(cats.Length>0)
{
foreach( class="tags" href="/tags/STRING.html" title=string>string cat in cats)
{
TreeNode node = new TreeNode();
node.Text = cat.Subclass="tags" href="/tags/STRING.html" title=string>string(cat.LastIndexOf("//")+1);
node.Tag = cat+"//";
node.ImageIndex = 1;
node.SelectedImageIndex = 2;
nodes.Add(node);
nodes[nodes.Count-1].EnsureVisible();
//不想一次性加载完所有子文件,则将此句代码注释
InsertTree(node.Nodes, cat);
}
}
}
}
class="tags" href="/tags/TREE.html" title=tree>treeSkill">