Click here to Skip to main content
13,050,450 members (94,935 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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
Updated 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2017
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