TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Scott Stewart
1.6k
189
18k
Routine is running twice
Mar 12 2012 6:54 PM
Could someone tell me why this routine runs twice?
private void PopulateTreeView(string county)
{
TreeNode rootNode;
DirectoryInfo info = new DirectoryInfo(@"C:\Users\Scot\Documents\Landman\Runsheets\" +county);
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);
}
}
I got his from an article on how to populate a treeview. The only change I made was to add a parameter to the call so I could limit the contents of the treeview. But it runs twice. When it finishes there are two top level nodes with the same name and all of the sub nodes are the same.
Thanks for your help.
Reply
Answers (
6
)
Image skew 3D with C#
GUI work , just need input, advice