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

Crashing on Setting Name Property

2 Answers 50 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ben Boger
Top achievements
Rank 1
Ben Boger asked on 11 Aug 2010, 11:04 PM
I have a function that builds my tree as needed. This works and it works well. The problem is that I would like to be able to use the function FindName from RadTreeView Item in another area. so all I add to my creating of the RadTreeViewItem is Name=newNodeString. 

When I do this the program crashes after return the list of nodes.

Take out that line everything, except the new feature I am trying to add, works fine.
  private static void BuildTree(ItemCollection items, List<string> treeNodes,int parentIndex)
{
    if (parentIndex >= treeNodes.Count) return;
     
    var newNodeString = treeNodes[parentIndex++];
 
    RadTreeViewItem newNode = (RadTreeViewItem)items.FirstOrDefault((i) => (string) ((RadTreeViewItem)i).Header == newNodeString);
 
    if(newNode == null)
    {
        newNode = new RadTreeViewItem {Header = newNodeString };
 
        if(treeNodes.Count == 0)//means this will be a child
        {
            newNode.Selected += (o, e) => { e.Handled = true; };
        }
        else
        {
            newNode.Selected += (o, e) =>
            {
                RadTreeViewItem item = o as RadTreeViewItem;
                if (item.HasItems)
                {
                    ((RadTreeViewItem)item.Items[0]).IsSelected = true;
                }
                e.Handled = true;
            };
            newNode.IsExpanded = true;
        }
        items.Add(newNode);
    }
 
    BuildTree(newNode.Items,treeNodes,parentIndex);
}
 

2 Answers, 1 is accepted

Sort by
0
Accepted
Miroslav
Telerik team
answered on 12 Aug 2010, 08:30 AM
Hi Ben Boger,

This error comes up most probably because the same name has already been given to a visual element. Two names cannot be the same within the same name scope.

Can this be in your case?

Greetings,
Miroslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ben Boger
Top achievements
Rank 1
answered on 12 Aug 2010, 02:41 PM
Originally I thought I had checked for that but upon a more thorough lookthrough I did indeed have duplicate names
Tags
TreeView
Asked by
Ben Boger
Top achievements
Rank 1
Answers by
Miroslav
Telerik team
Ben Boger
Top achievements
Rank 1
Share this question
or