Click here to Skip to main content
15,910,878 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am facing one problem when I am clicking on treeview nodes.
The problem is the first node is not activated next time.
I am dong image converting to text in my project. At that time I am populating treeview from system location and click node by node.

The problem is when I am clicking on the first node it shows the image in a picture box well.
Then after when I am clicking the next time the same image it is not working and the node is not activated.

What is the problem in my code?
My code is:

C#
    string fldr = ConfigurationSettings.AppSettings["IMGFOLDER"];
    formload()
{
  PopulateTreeview();
}
BtnImageShow()
{
DisplayImage();

}
  private void POpulateTreeview()
        {
            DirectoryInfo info = new DirectoryInfo(fldr);
            TreeNode root = new TreeNode(info.Name);
            root.Text = "";

            TreeNode node = new TreeNode();
            TrvImageFile.Nodes.Add(root);
            FileInfo[] subfileinfo = info.GetFiles("*.*");
            if (subfileinfo.Length > 0)
            {
                for ( j = 0; j < subfileinfo.Length; j++)
                {
                    root.Nodes.Add(subfileinfo[j].Name);
                }
            }

            TrvImageFile.ExpandAll();
        }
  DisplayImage()
{

fldr = string.Concat(fldr, "\\");
            fpath = string.Concat(fldr, TrvImageFile.SelectedNode.Text);
            try
            {
                rasterImageViewer1.Image = rc.Load(fpath);
            }
            catch (Exception ex)
            {
                MessageBox.Show("nothing  to select there ");
                MessageBox.Show(ex.Message);
            }
}

Anybody help me.
I am looking for standard code.
Please rectify my code and give some examples on this.
Posted
Updated 18-Aug-11 0:42am
v5

just try delay for loading image and clear it(i.e. rasterImageViewer1.Image=rc.load(nothing)... check the code, i didn't check it) before loading new image

not sure about the solution, but I face this sometime
 
Share this answer
 
I'm not clear if you are using a WinForm standard TreeView here, but, if you are, your code as shown should not compile:

1. TreeNode node = new TreeNode();

You create a new node here, but then never use it.

2. in your loop: root.Nodes.Add(subfileinfo[j].Name);

To add a new node to another node's TreeNodeCollection: you must create a new node in each iteration of the loop: here you are attempting to add a string, not a TreeNode, to the TreeNodeCollection of 'root.

You take it from here.
 
Share this answer
 
v2

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