put one listview and treeview control on a form, ive written this in c# and it may be or may not be what u want as. it first lists all drives in the list, then all folders under that, then listview gets filled with folder location.
Code:
public void FillTree(string Location)
{
//CLEAR HOLDERS
treeView1.Nodes.Clear();
listView1.Items.Clear();
//FIND ALL FILES IN FOLDER
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(Location);
foreach (System.IO.FileInfo f in dir.GetFiles("."))
{ //LOAD FILES
ListViewItem lSingleItem = listView1.Items.Add(f.Name);
//SUB ITEMS
lSingleItem.SubItems.Add(Convert.ToString(f.Length));
lSingleItem.SubItems.Add(f.Extension);
}
//FIND ALL DRIVES
TreeNode DrivesTop = treeView1.Nodes.Add("Available Drives");
DrivesTop.ImageIndex = 2;
DrivesTop.SelectedImageIndex = 2;
DrivesTop.Tag="";
String[] drives = Environment.GetLogicalDrives();
int NUM = drives.Length;
int p = 0;
while(p!=NUM)
{
String OutPut = Convert.ToString(drives[p]); // + Convert.ToString(drives[p].Length);
TreeNode Drives = DrivesTop.Nodes.Add(OutPut);
Drives.Tag = Convert.ToString(drives[p]);
Drives.ImageIndex = 1;
Drives.SelectedImageIndex = 1;
p++;
}
//FIND ALL FOLDERS IN FOLDER
TreeNode Main = treeView1.Nodes.Add("Folders in : " + Location);
Main.Tag = "";
Main.ImageIndex = 2;
Main.SelectedImageIndex = 2;
foreach (System.IO.DirectoryInfo g in dir.GetDirectories())
{ //LOAD FOLDERS
TreeNode MainNext = Main.Nodes.Add(g.FullName);
MainNext.Tag = (g.FullName);
}
//EXPAND TREE + GOTO TOP
treeView1.ExpandAll();
}
now to call this , do
Code:
string Location = Convert.ToString(txtPath.Text);
FillTree(Location);
and to change the listview files when folder,drive is clicked use this
Code:
private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
if (Convert.ToString(treeView1.SelectedNode.Tag) == "")
{//DO NOWT
}
else
{
txtPath.Text = Convert.ToString(treeView1.SelectedNode.Tag);
string Location = Convert.ToString(treeView1.SelectedNode.Tag);
FillTree(Location);
}
}
now as u posted in VB.NET and ive given code for c# , u can use this converter to change the code
http://www.developerfusion.com/utilities/convertcsharptovb.aspx
also u can remove the Main.ImageIndex = 2; + Main.SelectedImageIndex = 2; from the code as i have an imagelist associated with the treeview.
Enter your message below
Sign in or Join us (it's free).