Click here to Skip to main content
15,921,660 members
Home / Discussions / C#
   

C#

 
AnswerRe: How can I build a ListBox array? Pin
memix19-Mar-07 2:09
memix19-Mar-07 2:09 
GeneralRe: How can I build a ListBox array? Pin
Pete O'Hanlon19-Mar-07 2:20
mvePete O'Hanlon19-Mar-07 2:20 
QuestionTreeView Pin
sinosoidal19-Mar-07 0:21
sinosoidal19-Mar-07 0:21 
AnswerRe: TreeView Pin
JoeSharp19-Mar-07 0:32
JoeSharp19-Mar-07 0:32 
GeneralRe: TreeView Pin
sinosoidal19-Mar-07 0:37
sinosoidal19-Mar-07 0:37 
AnswerRe: TreeView Pin
sinosoidal19-Mar-07 0:49
sinosoidal19-Mar-07 0:49 
GeneralRe: TreeView Pin
joon vh.19-Mar-07 1:15
joon vh.19-Mar-07 1:15 
GeneralRe: TreeView Pin
sinosoidal19-Mar-07 5:12
sinosoidal19-Mar-07 5:12 
Hi,

I have just noticed that i dont have a consistent Tree.

I want to implement a tree to explore a directory which is going to be a library of files.

This is the code i have for it to be filled:

<br />
<br />
if (!Directory.Exists("Library"))<br />
            {<br />
                Directory.CreateDirectory("Library\Flash");<br />
                Directory.CreateDirectory("Library\Image");<br />
                Directory.CreateDirectory("Library\Movie");<br />
                Directory.CreateDirectory("Library\Url");<br />
            }<br />
<br />
private void initializeTree()<br />
        {<br />
            tvLibrary.Nodes.Clear();<br />
            tvLibrary.Nodes.Add(new TreeNode("Library"));<br />
            TreeNode tNode = new TreeNode();<br />
            tNode = tvLibrary.Nodes[0];<br />
<br />
            populateTree(Application.StartupPath + @"\Library", tNode, 0);<br />
            tvLibrary.ExpandAll();<br />
        }<br />
<br />
        private void populateTree(string root, TreeNode inTreeNode, int level)<br />
        {<br />
            TreeNode tNode;<br />
<br />
            try<br />
            {<br />
                // If there's no root folder, we can't insert anything<br />
                if (root.CompareTo("") == 0)<br />
                    return;<br />
<br />
                // Get information about the root folder.<br />
                System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(root);<br />
<br />
                // Retrieve the files and folders from the root folder.<br />
                DirectoryInfo[] dirs = dir.GetDirectories(); // Folders<br />
                FileInfo[] files = dir.GetFiles();           // Files<br />
<br />
                // Loop through all folders in the root folder and insert them<br />
                foreach (System.IO.DirectoryInfo di in dirs)<br />
                {<br />
                    inTreeNode.Nodes.Add(new TreeNode(di.Name));<br />
                    //inTreeNode.Nodes.Add(di.Name, di.Name, this.folderIndex);<br />
                    <br />
                    tNode = inTreeNode.Nodes[level];<br />
                    populateTree(root + @"\" + di.Name, tNode, level + 1);<br />
                }<br />
<br />
                // Loop through all the files in the root folder<br />
                foreach (System.IO.FileInfo fi in files)<br />
                {<br />
                    inTreeNode.Nodes.Add(new TreeNode(fi.Name));<br />
                }<br />
            }<br />
            catch (System.Exception err)<br />
            {<br />
                MessageBox.Show("Error: " + err.Message);<br />
            }<br />
        }<br />


I detected two problems. If i have files in the Images directory they appear normally, under Images sub folder inside the main node, Library.

However, if i have files under Movies, or Urls folders, those files appear under the Images sub folder.

The other problem is that if create a folder inside the Images folder, a error happens, which i think its about the level depthness.

I tried to understand this tree concept but its quite strange.

Can someone try to expalin me what is going on?

Thx,

Nuno
GeneralRe: TreeView Pin
joon vh.19-Mar-07 5:31
joon vh.19-Mar-07 5:31 
QuestionHow to store sensitive data? Pin
Akiratf19-Mar-07 0:20
Akiratf19-Mar-07 0:20 
AnswerRe: How to store sensitive data? Pin
joon vh.19-Mar-07 1:06
joon vh.19-Mar-07 1:06 
AnswerRe: How to store sensitive data? Pin
m@u19-Mar-07 4:21
m@u19-Mar-07 4:21 
AnswerRe: How to store sensitive data? Pin
Vasudevan Deepak Kumar19-Mar-07 6:32
Vasudevan Deepak Kumar19-Mar-07 6:32 
AnswerRe: How to store sensitive data? Pin
Akiratf19-Mar-07 22:04
Akiratf19-Mar-07 22:04 
QuestionReading value from a variabile Pin
Andrei Ungureanu19-Mar-07 0:13
Andrei Ungureanu19-Mar-07 0:13 
AnswerRe: Reading value from a variabile Pin
Pete O'Hanlon19-Mar-07 0:17
mvePete O'Hanlon19-Mar-07 0:17 
GeneralRe: Reading value from a variabile Pin
Andrei Ungureanu19-Mar-07 0:30
Andrei Ungureanu19-Mar-07 0:30 
GeneralRe: Reading value from a variabile Pin
Colin Angus Mackay19-Mar-07 0:39
Colin Angus Mackay19-Mar-07 0:39 
GeneralRe: Reading value from a variabile Pin
Andrei Ungureanu19-Mar-07 0:47
Andrei Ungureanu19-Mar-07 0:47 
GeneralRe: Reading value from a variabile Pin
Pete O'Hanlon19-Mar-07 0:55
mvePete O'Hanlon19-Mar-07 0:55 
GeneralRe: Reading value from a variabile Pin
Colin Angus Mackay19-Mar-07 0:56
Colin Angus Mackay19-Mar-07 0:56 
GeneralRe: Reading value from a variabile Pin
Pete O'Hanlon19-Mar-07 1:01
mvePete O'Hanlon19-Mar-07 1:01 
GeneralRe: Reading value from a variabile Pin
Colin Angus Mackay19-Mar-07 0:55
Colin Angus Mackay19-Mar-07 0:55 
GeneralRe: Reading value from a variabile Pin
Andrei Ungureanu19-Mar-07 1:00
Andrei Ungureanu19-Mar-07 1:00 
AnswerRe: Reading value from a variabile Pin
Colin Angus Mackay19-Mar-07 0:37
Colin Angus Mackay19-Mar-07 0:37 

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.