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

Delete RadTreeView Items with Delete Key

1 Answer 197 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 13 Jun 2011, 02:24 PM
Telerik support,

I have a RadTreeView that is populated with DataBinding to an XML data file.  I use a Hierarchical DataTemplate in the XAML code to populate the Tree.  I would like to use the following in the C# code-behind to delete elements with the delete key.  This works fine for all of the first-level nodes in the Tree.  I would like to be able to select child items also and delete them in the same way.  The child items are created with DragAndDrop.

Here is the code to delete the parent items:

void MyView_KeyDown(object sender, KeyEventArgs e)
        {          
            if (e.Key.Equals(Key.Delete))
            {
                IList source = this.MyView.ItemsSource as IList;
                source.Remove(MyView.SelectedItem);                               
            }
        }

How can I change this to delete the child items also?  I have looked at some of the examples in the forum, and I found

foreach

 

 

(MyItem item in MyView.ItemsSource)

 

 

    {

 

 

 

    foreach (MyItem child in item.Children)

 

 

        {

 

            source.Remove(MyView.SelectedItem);

 

        }

 

    }


but I don't know what to use for item.Children in the 2nd foreach statement if this is the best way to find all child nodes.

Thanks,
Scott

1 Answer, 1 is accepted

Sort by
0
Scott
Top achievements
Rank 1
answered on 14 Jun 2011, 05:10 PM
I figured it out.  Thanks anyway.
Scott
Tags
TreeView
Asked by
Scott
Top achievements
Rank 1
Answers by
Scott
Top achievements
Rank 1
Share this question
or