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

Problem with dynamically creating a treeview item

1 Answer 25 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Angeli
Top achievements
Rank 1
Angeli asked on 02 May 2011, 08:28 AM
Hi Telerik!

How can I add a new rad treeview item in a selected container. I'm having problems with this code here:
private void AddItem(RoutedEventArgs e)
{  
    RadTreeView treeViewItem = (RadTreeView)e.OriginalSource;
     
    if (treeViewItem.SelectedContainer == null)
    {
        treeViewItem.SelectedContainer.Items.Add(new RadTreeViewItem()
        {
            Header = "New Section", IsInEditMode = true
        });
                     
        return;
    }
     
    treeViewItem.SelectedContainer.Items.Add(new RadTreeViewItem()
    {
        Header = "New Section", IsInEditMode = true
    });
     
    treeViewItem.SelectedContainer.IsExpanded = true;
     
}

It runs but nothing happens.

Basically, I'm trying to create a tree view dynamically.

1 Answer, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 05 May 2011, 11:54 AM
Hi Angeli,

I am not sure I understand this part of the code you sent:
if (treeViewItem.SelectedContainer == null)
{
    treeViewItem.SelectedContainer.Items.Add(new RadTreeViewItem()
    {
        Header = "New Section", IsInEditMode = true
    });
                  
    return;
}
You check that the SelectedContainer is null and then you try to add items to its Items collection. Am I missing something here?

However, I believe that in your case it would be best to take advantage of the LoadOnDemand feature of the RadTreeView control. You can find more info about it here or you can test its demo here.

Best wishes,
Tina Stancheva
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
Tags
GridView
Asked by
Angeli
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Share this question
or