Click here to Skip to main content
15,903,033 members
Home / Discussions / C#
   

C#

 
QuestionVisual Studio 2005 Pin
Korken_Bro9-Mar-07 2:25
Korken_Bro9-Mar-07 2:25 
AnswerRe: Visual Studio 2005 Pin
Colin Angus Mackay9-Mar-07 2:27
Colin Angus Mackay9-Mar-07 2:27 
GeneralRe: Visual Studio 2005 Pin
Korken_Bro9-Mar-07 2:38
Korken_Bro9-Mar-07 2:38 
AnswerRe: Visual Studio 2005 Pin
Stefan Troschuetz9-Mar-07 2:59
Stefan Troschuetz9-Mar-07 2:59 
AnswerRe: Visual Studio 2005 Pin
Wayne Phipps9-Mar-07 4:42
Wayne Phipps9-Mar-07 4:42 
GeneralRe: Visual Studio 2005 Pin
Korken_Bro9-Mar-07 7:04
Korken_Bro9-Mar-07 7:04 
AnswerRe: Visual Studio 2005 Pin
Thomas Stockwell9-Mar-07 12:42
professionalThomas Stockwell9-Mar-07 12:42 
QuestionProblem Creating TreeView Pin
t4ure4n9-Mar-07 1:06
t4ure4n9-Mar-07 1:06 
I am creating a TreeView which lists all the directories and ".xls" in a given directory

I have created my own version of TreeView and TreeNode, just to allow my TreeNodes to have some extra information (path of the file or the directory)
The problem i am facing is once done the processing the Tree View does not show mw the nodes in the Tree. if i check the count it is OK (same no of files and directories i have) but they don't show up on thew form. So i am providing my code in a hope that some1 will have an idea what i am doing wrong.

The first part is the method that create the treeview(my version), and tries to copy the nodes from it to the TreeView (.net) .
private void createTree()
  {
     g_ReportsFolder = Directory.GetCurrentDirectory() + "\\Reports2";
     ReportTree rtree = new ReportTree(g_ReportsFolder);
        foreach (ReportNode rNode in rtree.Nodes)
           {
               this.tvReports2.Nodes.Add(rNode);
            }

  }

Note: If I use
this.tvReports2.Nodes.Add(rNode.Text);
instead of
this.tvReports2.Nodes.Add(rNode);
I can view the nodes in the treeview

This is the TreeView class that creates the list of nodes by using a recursive function createTree(DirectoryInfo p_Directory)
public class ReportTree : TreeView
    {
        private string ReportsFolder = "";
        private DirectoryInfo Directory = null;

        public ReportTree(string p_ReportsFolder)
        {
            ReportsFolder = p_ReportsFolder;
            Directory = new DirectoryInfo(ReportsFolder);
            createTree(Directory);
            string s = this.Name;
        }

        private void createTree(DirectoryInfo p_Directory)
        {
            DirectoryInfo l_DirctoryInfo = null; 
            //Lookout for the children of the Directory
            foreach (FileSystemInfo Report in p_Directory.GetFileSystemInfos())
            {
                if (isDirectory(Report))
                {
                    createDirectoryNode(Report);
                    l_DirctoryInfo = new DirectoryInfo(Report.FullName);
                    createTree(l_DirctoryInfo);
                }
                else if (isXLSFile(Report))
                {
                    createFileNode(Report);
                }
                else
                {
                    continue;
                }
            }
        }

        private bool isDirectory(FileSystemInfo p_FSI)
        {
            if (p_FSI.Attributes == FileAttributes.Directory)
                return true;
            else
                return false;
        }

        private bool isXLSFile(FileSystemInfo p_FSI)
        {
            if (p_FSI.Attributes == FileAttributes.Archive && p_FSI.Extension == ".xls")
                return true;
            else
                return false;
        }

        private void createDirectoryNode(FileSystemInfo p_DirInfo)
        {
            string l_Text = p_DirInfo.Name;
            string l_Name = p_DirInfo.Name.Replace(" ", "").Replace("'", "").Trim();
            string l_Path = p_DirInfo.FullName;

            //Create a new Report Node (Customization of the tree node class)            
            this.Nodes.Add(new ReportNode(true, l_Name, l_Text, l_Path));
        }

        private void createFileNode(FileSystemInfo p_FileInfo)
        {
            string l_Text = p_FileInfo.Name.Remove(p_FileInfo.Name.IndexOf(".xls"));
            string l_Name = l_Text.Replace(" ", "").Replace("'", "").Trim();
            string l_Path = p_FileInfo.FullName;
            
            //Create a new Report Node (Customization of the tree node class)
            this.Nodes.Add(new ReportNode(false, l_Name, l_Text, l_Path));
        }
    }

This is the class that is customization of the TreeNode. I used this to have Some Extra info like path of the file with the node
public class ReportNode : TreeNode
    {        
        public bool isDirectory;        
        public string NodeName;
        public string NodeText;
        public string NodePath;
        
        public ReportNode(bool p_isDirectory, string p_Name, string p_Text, string p_Path)
        {
            this.isDirectory = p_isDirectory;
            this.NodeName = p_Name;
            this.NodeText = p_Text;
            this.NodePath = p_Path;

            //adding data to the base (tree Node) because .NET doesn't not to pick up the attributes and override them
            this.Text = this.NodeText;
            this.Name = this.NodeName;
        }
    }




o O º(`'·.,(`'·., ☆,.·''),.·'')º O o°
»·'"`»* *☆ t4ure4n ☆* *«·'"`«
°o O º(,.·''(,.·'' ☆`'·.,)`'·.,)º O o°

AnswerRe: Problem Creating TreeView Pin
tgrt9-Mar-07 2:35
tgrt9-Mar-07 2:35 
QuestionHighlighting a selected text. Pin
SakthiSurya9-Mar-07 0:47
SakthiSurya9-Mar-07 0:47 
AnswerRe: Highlighting a selected text. Pin
N a v a n e e t h9-Mar-07 0:53
N a v a n e e t h9-Mar-07 0:53 
AnswerRe: Highlighting a selected text. Pin
irrdev9-Mar-07 21:38
irrdev9-Mar-07 21:38 
QuestionHow to write a memory resident application in C#.NET Pin
Mutyala Rao9-Mar-07 0:43
Mutyala Rao9-Mar-07 0:43 
AnswerRe: How to write a memory resident application in C#.NET Pin
Eytukan9-Mar-07 1:50
Eytukan9-Mar-07 1:50 
GeneralRe: How to write a memory resident application in C#.NET Pin
Mutyala Rao9-Mar-07 20:27
Mutyala Rao9-Mar-07 20:27 
Questiondatagridview Pin
Ruchi039-Mar-07 0:30
Ruchi039-Mar-07 0:30 
AnswerRe: datagridview Pin
nyogeswar9-Mar-07 1:20
nyogeswar9-Mar-07 1:20 
QuestionHow to get all the software install in the machine Pin
Niiiissssshhhhhuuuuu9-Mar-07 0:04
Niiiissssshhhhhuuuuu9-Mar-07 0:04 
AnswerRe: How to get all the software install in the machine [modified] Pin
MoustafaS9-Mar-07 3:26
MoustafaS9-Mar-07 3:26 
AnswerRe: How to get all the software install in the machine Pin
Thomas Stockwell9-Mar-07 12:45
professionalThomas Stockwell9-Mar-07 12:45 
QuestionHow to Retrieve Primary Key Column from an Existing Table in MsAcess Pin
BLekha8-Mar-07 22:04
BLekha8-Mar-07 22:04 
Questionvery simple question: what is the purpose of & in "" Pin
dino20948-Mar-07 22:00
dino20948-Mar-07 22:00 
AnswerRe: very simple question: what is the purpose of & in "" Pin
Stefan Troschuetz8-Mar-07 22:12
Stefan Troschuetz8-Mar-07 22:12 
AnswerRe: very simple question: what is the purpose of & in "" Pin
stancrm8-Mar-07 22:13
stancrm8-Mar-07 22:13 
QuestionUsercontrol and focus? Pin
Snowjim8-Mar-07 21:43
Snowjim8-Mar-07 21:43 

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.