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
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
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