Delete RadTreeView Items with Delete Key

2 posts, 0 answers
  1. Scott
    Scott avatar
    7 posts
    Member since:
    May 2011

    Posted 13 Jun 2011 Link to this post

    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
  2. Scott
    Scott avatar
    7 posts
    Member since:
    May 2011

    Posted 14 Jun 2011 Link to this post

    I figured it out.  Thanks anyway.
    Scott
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top