Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
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
Updated 1-May-13 4:24am
v2

1 solution

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.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900