views:

75

answers:

2

Hello,

I am implementing one of the common scenerios of a TreeView control and I am using a drives, files and folders. to make a File System. That means each node potentially has a path.

Problem is, we have the ensureVisible method but am not entirely convinced this does what it says it does. There is no explicit 'setVisible' to false property. This meas by default all TreeNodes are going to be Visible !!!

Can someone come up with solution that proves it does work?

Heres a method stub am working with?

    public void selectTreeNodeFromPath(string path)
    { 
        //char[] delimiters = new char[]{ '\\' };
        //string[] pathArray = path.Split(delimiters);
        //int numberOfLvlsToProbe = pathArray.Length;

        // foreach (TreeNode node in treeDrives.Nodes)
        //   {}
    }

You can see that I have I started to attack this problem but I have hit a tumbling block after a simple test case yielded NO-EFFECT !!!

Forgive me if i'm being an idiot.

+1  A: 

TreeNodes will be visible depending on the expanded condition of their parent nodes and where the scroll position of the control is. What the EnsureVisible method does is expand the proper parents and scroll the control to the specified node.

Assuming that your tree has already been populated with the nodes, you should be able to call EnsureVisible on the last node and the control will expand all the parents. Then you can set SelectedNode to have that node be selected.

msergeant
A: 
IbrarMumtaz