This is a migrated thread and some comments may be shown as answers.

Is it possible to change the PathSeparator?

4 Answers 109 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jim
Top achievements
Rank 1
Jim asked on 08 Aug 2008, 04:21 PM
Hi guys, hopefully this is an easy one.

I am performing 'lazy loading' on my tree view control, so only the highest level nodes are loaded at any given time.  However, we may already have a selected node somewhere deep in the tree when our page loads, so I want to go ahead and select it for the user programmatically.  The following code does just that but throws exceptions when there are '/' characters in some of the nodes display values.

private void OpenTreeToNode(string nodeValue) 
    if (nodeValue.Length > 0) 
    { 
        FacilityBE facility = new FacilityBE(int.Parse(nodeValue)); 
        string valuePath = ""
 
        List<FacilityBE> ancestorFacilities = facility.GetAncestors(true); 
 
        foreach (FacilityBE ancestorFacility in ancestorFacilities) 
        { 
            if (ancestorFacility != ancestorFacilities[0]) 
            { 
                valuePath += "/"; 
            } 
            valuePath += ancestorFacility.ID.ToString(); 
            RadTreeNode node = Tree.FindNodeByValue(ancestorFacility.ID.ToString()); 
            node.Expanded = true
            this.FillChildNodes(node); 
        } 
        Tree.FindNodeByValue(nodeValue).Selected = true
    } 
 

So the question is, how can I change my ValuePathSeparator, or perform this same functionality without using it.

Thanks for your time.


4 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 11 Aug 2008, 01:03 PM
Hello Jim,

Could you provide more details on the case? For example, when these exceptions are thrown? Could you provide the steps for reproducing them? Finally, what is the ValuePathSeparator?

Regards,
Simon
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jim
Top achievements
Rank 1
answered on 11 Aug 2008, 03:07 PM
I did miss speak on my last post.  I would like to change the PathSeparator, not the ValuePathSeparator (which does not actually exist).

http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.pathseparator.aspx

When speaking of the default ASP.net TreeView control.

So, as I understand it, nodes can be located through a string path where node values are separated by delimiters.  So, just as a for instance with the default separator.

"USA/Missouri/Cox South/Building 227/Room 14"

Would be a node path that starts with top level node USA and drills down to Room 14.  Now, when I check this path for the first time, nothing below USA exists on the grid, so checking for this path will return null (no node found). Therefore, I have to parse it out and populate the tree for the nodes that I require to continue my search (what my previous post's function accomplishes).  Note that this also seems to work for your RadTreeView control.

Where we run into trouble is with Node Paths like.

"USA/Missouri/Cox South/Building 227/ER / Urgent Care"

where "ER / Urgent Care" is one node, obviously, this will be parsed incorrectly, and I will receive a null return value when I get to the step to search for:

"USA/Missouri/Cox South/Building 227/ER "

The quickest solution I have come up with is to just change that delimiter to something I know the users have no need for, like "||".  However, I can not locate this property on your RadTreeView control.

Thanks again for your time,
0
Accepted
Atanas Korchev
Telerik team
answered on 11 Aug 2008, 03:14 PM
Hi Jim,

RadTreeView does not use any separator internally. The FindNodeByValue method just traverses all nodes and checks their Value property for the specified argument.

The FullPath property returns something similar to what you need. However we don't use that property internally. Alternatively to the FullPath property you can use the GetFullPath method which accepts a separator. In a word there should be no need to change any separator as long as you use the FindNodeByValue method.

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jim
Top achievements
Rank 1
answered on 11 Aug 2008, 11:50 PM
That's exactly what I needed to get me thinking in line with the Telerik control.  Thanks again.  In case it helps anybody else, this is an equivelant function to the one posted above that is not dependent on a PathSeparator. 

NOTE: parameter nodeValue here is just the integer ID for the node we are looking for, instead of the fully qualified string path in the previous example.

private void OpenTreeToNode(int nodeValue) 
    FacilityBE fac = new FacilityBE(nodeValue); 
    List<FacilityBE> ancestors = fac.GetAncestors(true); 
 
    foreach (FacilityBE facility in ancestors) 
    { 
        RadTreeNode node = Tree.FindNodeByValue(facility.ID.ToString()); 
        if (node != null) 
        { 
            if (facility != ancestors[ancestors.Count - 1]) 
            { 
                node.Expanded = true
                FillChildNodes(node); 
            } 
            else 
            { 
                node.Selected = true
                this.SelectedID = node.Value; 
            } 
        } 
    } 
}

Thanks again for your time,
Tags
TreeView
Asked by
Jim
Top achievements
Rank 1
Answers by
Simon
Telerik team
Jim
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or