Click here to Skip to main content
Rate this: bad
good
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()
    {
        InitializeComponent();
 
        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)
    {
        if(e.Node.Name.EndsWith("txt"))
        {
            this.richTextBox1.Clear();
            StreamReader reader = new StreamReader(e.Node.Name);
            this.richTextBox1.Text = reader.ReadToEnd();
            reader.Close();
        }
    }
Posted 1-May-13 5:02am
Edited 1-May-13 5:24am
v2

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
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)



Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 1 May 2013
Copyright © CodeProject, 1999-2014
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