Suggest i have this treeview:
<TreeView Height="295" HorizontalAlignment="Left" Margin="11,58,0,0" Name="treeView1" VerticalAlignment="Top" Width="260" Grid.ColumnSpan="2">
<TreeViewItem Header="Boek" Name="BoekenLijst" Width="260" HorizontalContentAlignment="Stretch" />
<TreeViewItem Header="CD" Name="CDLijst" Width="260" />
<TreeViewItem Header="DVD" Name="DVDLijst" Width="260" />
</TreeView>
In the 3 Treeviewitems I dynamically put treeviewitems in with checkboxes on it.
I am trying to remove the selected items, at the moment i did this:
TreeViewItem parent = treeView1.SelectedItem as TreeViewItem;
//What do i need to put here so i can remove the selected childs?
If you want to remove the selected item directly, try:
treeView1.Items.Remove(treeView1.SelectedItem);
If you want to delete all sub items of the selected item:
ObservableCollection<TreeViewItem> helper = new ObservableCollection<TreeViewItem>();
foreach(TreeViewItem item in treeView1.SelectedItem.Items)
{
helper.Add(item);
}
foreach(TreeViewItem item in helper)
{
treeView1.SelectedItem.Items.Remove(item);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.