下載方法:http://hovertree.com/hvtart/bjae/ldm2365l.htm
C#代碼:
string m_selectPath;
if (folderBrowserDialog_hvt.ShowDialog() == DialogResult.OK)
{
listView_hoverTree.Clear();
m_selectPath = folderBrowserDialog_hvt.SelectedPath;
DirectoryInfo TheFolder = new DirectoryInfo(m_selectPath);
listView_hoverTree.BeginUpdate(); //數據更新,UI暫時掛起,直到EndUpdate繪制控件,可以有效避免閃爍並大大提高加載速度
//listView_hoverTree.View = View.Details;//設置視圖
//listView_hoverTree.SmallImageList = imageList;//設置圖標
//添加列
listView_hoverTree.Columns.Add("名稱", 300, HorizontalAlignment.Left);
listView_hoverTree.Columns.Add("路徑", 300, HorizontalAlignment.Left);
// ListViewItem m_item;
foreach (DirectoryInfo di in TheFolder.GetDirectories())//遍歷文件夾下所有文件夾
{
var m_item = new ListViewItem();
m_item.ImageIndex = 0; //通過與imageList綁定,顯示imageList中第i項圖標
m_item.Text = di.Name;
m_item.SubItems.Add(di.FullName); //路徑 何問起
//添加行
listView_hoverTree.Items.Add(m_item);
}
foreach (FileInfo fi in TheFolder.GetFiles())//遍歷文件夾下所有文件
{
var m_item = new ListViewItem();
m_item.ImageIndex = 1;
m_item.Text = fi.Name;
m_item.SubItems.Add(fi.FullName);
//添加行
listView_hoverTree.Items.Add(m_item);
}
listView_hoverTree.EndUpdate();//結束數據處理,UI界面一次性繪制。
}