Click here to Skip to main content
11,582,800 members (71,302 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C Treeview
I am unable to display the text file contents in richtextbox. When the project is started it runs the project without any error. I also found when I tried inserting brekpoint into treeView1_AfterSelect, the control doesn't go there
    public Form1()
        DirectoryInfo directoryInfo = new DirectoryInfo(@"C:\Users\Shahul\Documents\Visual Studio 2010\Projects\TreeView\TreeView\bin\FileExplorer")
        if (directoryInfo.Exists)
            treeView1.AfterSelect += treeView1_AfterSelect;
            BuildTree(directoryInfo, treeView1.Nodes);
    private void BuildTree(DirectoryInfo directoryInfo, TreeNodeCollection addInMe)
        TreeNode curNode = addInMe.Add(directoryInfo.Name);
        foreach (FileInfo file in directoryInfo.GetFiles())
            curNode.Nodes.Add(file.FullName, file.Name);
        foreach (DirectoryInfo subdir in directoryInfo.GetDirectories())
            BuildTree(subdir, curNode.Nodes);
    private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
            StreamReader reader = new StreamReader(e.Node.Name);
            this.richTextBox1.Text = reader.ReadToEnd();
Posted 1-May-13 4:02am
Edited 1-May-13 4:24am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Check to make sure the AfterSelect event is wired up for treeView1. In the properties for treeView1, select the Events icon to display the events for the TreeView. Look in the AfterSelect element and if it's not set, link it to your method there.
ShaHam11 at 1-May-13 10:50am
@Pete O'Hanlon I have already linked ..still the same

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 335
1 Sergey Alexandrovich Kryukov 220
2 Andy Lanng 124
3 virusstorm 109
4 Kornfeld Eliyahu Peter 90
0 OriginalGriff 1,358
1 Sergey Alexandrovich Kryukov 970
2 Abhinav S 671
3 F-ES Sitecore 505
4 Suvendu Shekhar Giri 448

Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100