Mike Eghtebas
asked on
small app debug, c#, vs2012
I am following the link below to create file/folder tree-view similar to file explore:
http://msdn.microsoft.com/en-us/library/ms171645%28v=vs.80%29.aspx
What I have built is not working. I wonder if you could possibly take a look at this 60KB file at: https://onedrive.live.com/?cid=420CDD6A13807C9B&id=420CDD6A13807C9B%21116 to see how I may be able to fix this:
http://msdn.microsoft.com/en-us/library/ms171645%28v=vs.80%29.aspx
What I have built is not working. I wonder if you could possibly take a look at this 60KB file at: https://onedrive.live.com/?cid=420CDD6A13807C9B&id=420CDD6A13807C9B%21116 to see how I may be able to fix this:
whats the issue you are having?
adding some fix here & there... here we go:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace FilesAndFolderInTreeView
{
public partial class Form1 : Form
{
private void PopulateTreeView()
{
TreeNode rootNode;
DirectoryInfo info = new DirectoryInfo(@"C:\");
if (info.Exists)
{
rootNode = new TreeNode(info.Name);
rootNode.Tag = info;
GetDirectories(info.GetDirectories(), rootNode);
treeView1.Nodes.Add(rootNode);
}
}
private void GetDirectories(DirectoryInfo[] subDirs, TreeNode nodeToAddTo)
{
TreeNode aNode;
DirectoryInfo[] subSubDirs;
foreach (DirectoryInfo subDir in subDirs)
{
aNode = new TreeNode(subDir.Name, 0, 0);
aNode.Tag = subDir;
aNode.ImageKey = "folder";
subSubDirs = subDir.GetDirectories();
if (subSubDirs.Length != 0)
{
GetDirectories(subSubDirs, aNode);
}
nodeToAddTo.Nodes.Add(aNode);
}
}
public Form1()
{
InitializeComponent();
PopulateTreeView();
//this.treeView1.NodeMouseClick += new TreeNodeMouseClickEventHandler(this.treeView1_NodeMouseClick);
}
}
}
ASKER
Sorry about for not stating the problem correctly. It doesn't have error. I just doesn't populate the controls (TreeView or ListView).
without writing any line of code, how come can you expect it to run like an explorer?
anyways, just copy paste the code ^^^ replacing your whole code...
anyways, just copy paste the code ^^^ replacing your whole code...
ASKER
I have totally messed up this application. I replaced old Form1 with another Form2 (then renamed it to Form1) in the process most of my code was deleted. I will go for a run now. After that break, I will shape it up so we can continue with it.
Mike
Mike
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Hain,
I am sure what you are saying would work. But unfortunately I have deleted the entire project and started all over again which in a sense is good practice for me.
Good news is that it is working now.
Thanks,
Mike
I am sure what you are saying would work. But unfortunately I have deleted the entire project and started all over again which in a sense is good practice for me.
Good news is that it is working now.
Thanks,
Mike