Crashing on Setting Name Property

3 posts, 1 answers
  1. Ben Boger
    Ben Boger avatar
    19 posts
    Member since:
    May 2010

    Posted 11 Aug 2010 Link to this post

    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. Answer
    Miroslav
    Admin
    Miroslav avatar
    922 posts

    Posted 12 Aug 2010 Link to this post

    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
  3. Ben Boger
    Ben Boger avatar
    19 posts
    Member since:
    May 2010

    Posted 12 Aug 2010 Link to this post

    Originally I thought I had checked for that but upon a more thorough lookthrough I did indeed have duplicate names
Back to Top