Click here to Skip to main content
15,887,746 members
Home / Discussions / C#
   

C#

 
AnswerRe: C# Save the the last entered data on application exit and reload it on application start. Pin
wjp_auhtm12-Aug-09 21:07
wjp_auhtm12-Aug-09 21:07 
GeneralRe: C# Save the the last entered data on application exit and reload it on application start. Pin
maheesh12-Aug-09 22:16
maheesh12-Aug-09 22:16 
GeneralRe: C# Save the the last entered data on application exit and reload it on application start. Pin
wjp_auhtm13-Aug-09 0:22
wjp_auhtm13-Aug-09 0:22 
GeneralRe: C# Save the the last entered data on application exit and reload it on application start. Pin
maheesh13-Aug-09 1:32
maheesh13-Aug-09 1:32 
QuestionAccessing/reading .TTF Pin
dell22412-Aug-09 16:17
dell22412-Aug-09 16:17 
QuestionVisio file to pdf Pin
StefCarle12-Aug-09 15:19
StefCarle12-Aug-09 15:19 
AnswerRe: Visio file to pdf Pin
Christian Graus12-Aug-09 16:45
protectorChristian Graus12-Aug-09 16:45 
QuestionPopulate TreeView from a flat file Pin
ccsalway12-Aug-09 11:48
ccsalway12-Aug-09 11:48 
Hi people!

I have been trying for days to populate a treeview from a particular structure.

The text file i have to work with is similar to this:

root
root/folder1
root/folder2
root/folder2/subfolder1
root/folder2/subfolder2/subfolder3
root/folder3/subfolder4
root/folder4

Which I can almost get to populate a treeview with. In fact, i can get to root/folder2/subfolder2/subfolder3, and then it wont display the root/folder3/subfolder4 because it hasnt created the root/folder3 path first!

There must be an easier way to do this!!!

Here's my '2 evenings of working on this now', code so far:

ArrayList paths = {the file split line by line into an arraylist}

private void Run()
{
    treeView1.Nodes.Add("root");
    Buildtree("root", treeView1.Nodes[0]);
}
    
private void Buildtree(String path, TreeNode parentNode)
{
    ArrayList directories = GetDirectories(path);
    if (directories.Count != 0)
    {
        foreach (string directory in directories)
        {
            TreeNode node = new TreeNode(directory.Remove(0, path.Length + 1));
            parentNode.Nodes.Add(node);

            Buildtree(directory, node);
        }
    }
}

private ArrayList GetDirectories(string parentPath)
{
    ArrayList directories = new ArrayList();
    foreach (string path in paths)
    {
        if (path.StartsWith(parentPath))
        {
            bool hasSubdir = false;

            if (path.Contains('/') && (path.Length > parentPath.Length))
            {
                int startpos = parentPath.Length + 1;
                string leftover = path.Substring(startpos, path.Length - startpos);
                if (!string.IsNullOrEmpty(leftover) && leftover.Contains('/')) hasSubdir = true;
            }

            if (!hasSubdir && (path != parentPath))
                directories.Add(path);
        }
    }
    return directories;
}


Im going bonkers over this!!
AnswerRe: Populate TreeView from a flat file Pin
PIEBALDconsult12-Aug-09 13:41
mvePIEBALDconsult12-Aug-09 13:41 
AnswerRe: Populate TreeView from a flat file Pin
Luc Pattyn12-Aug-09 14:07
sitebuilderLuc Pattyn12-Aug-09 14:07 
GeneralRe: Populate TreeView from a flat file Pin
ccsalway12-Aug-09 20:14
ccsalway12-Aug-09 20:14 
GeneralRe: Populate TreeView from a flat file Pin
Luc Pattyn13-Aug-09 2:12
sitebuilderLuc Pattyn13-Aug-09 2:12 
GeneralRe: Populate TreeView from a flat file Pin
ccsalway13-Aug-09 2:13
ccsalway13-Aug-09 2:13 
GeneralRe: Populate TreeView from a flat file Pin
Luc Pattyn13-Aug-09 3:08
sitebuilderLuc Pattyn13-Aug-09 3:08 
QuestionAdd shortcuts to a system tray application Pin
LordZoster12-Aug-09 9:53
LordZoster12-Aug-09 9:53 
AnswerRe: Add shortcuts to a system tray application Pin
Henry Minute12-Aug-09 10:23
Henry Minute12-Aug-09 10:23 
GeneralRe: Add shortcuts to a system tray application Pin
LordZoster12-Aug-09 10:34
LordZoster12-Aug-09 10:34 
AnswerRe: Add shortcuts to a system tray application Pin
LordZoster12-Aug-09 10:37
LordZoster12-Aug-09 10:37 
QuestionEncryption with tcpclient and tcplistner? Pin
Druuler12-Aug-09 8:43
Druuler12-Aug-09 8:43 
AnswerRe: Encryption with tcpclient and tcplistner? Pin
Leonardo Muzzi12-Aug-09 10:16
Leonardo Muzzi12-Aug-09 10:16 
QuestionHow to send file to com1 port ? Pin
E_Gold12-Aug-09 7:28
E_Gold12-Aug-09 7:28 
AnswerRe: How to send file to com1 port ? Pin
stancrm12-Aug-09 7:47
stancrm12-Aug-09 7:47 
Question[Message Deleted] Pin
neha_rai12-Aug-09 6:38
neha_rai12-Aug-09 6:38 
AnswerRe: Ellipse fitting Pin
Rick York12-Aug-09 6:59
mveRick York12-Aug-09 6:59 
QuestionDelegates/Events in Client/Server apps Pin
Nigel Mackay12-Aug-09 5:57
Nigel Mackay12-Aug-09 5:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.