Share via

How to remove the root node from TreeView bound to DataSet With HierarchicalDataTemplate

Julius Max 1 Reputation point
2021-08-07T16:48:04.53+00:00

Good evening,

I Have the working code XAML + Powershell:

<TabItem Header="Tasks" Visibility="Collapsed" Name="TabTasks">
<TabItem.Resources>
<HierarchicalDataTemplate x:Key="ClosuresDataTemplate" ItemsSource="{Binding Status2Closure}" >
<Grid>
<CheckBox IsChecked="True" Content="{Binding TaskStatus}"/>
<CheckBox IsChecked="True" Content="{Binding TaskClosure}"/>
</Grid>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="StatusDataTemplate" ItemsSource="{Binding Types2Status}" ItemTemplate="{StaticResource ClosuresDataTemplate}">
<CheckBox IsChecked="True" Content="{Binding TaskType}"/>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key="TypesDataTemplate" ItemsSource="{Binding TasksTypes}" ItemTemplate="{StaticResource StatusDataTemplate}">
<TextBlock Text="Task types, status and closure reason tree"/>
</HierarchicalDataTemplate>
</TabItem.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="20"/>
<RowDefinition Height="20"/>
<RowDefinition Height="250"/>
<RowDefinition Height="20"/>
<RowDefinition Height="250"/>
<RowDefinition Height="20*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1000*"/>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<TreeView Name="TreeTest" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="1" Grid.RowSpan="6" HorizontalContentAlignment="Stretch" Background="LightSlateGray" ItemTemplate="{StaticResource TypesDataTemplate}"/>
</Grid>
</TabItem>

Data send by PS with:
$wpf.TreeTest.ItemsSource = $dts.DefaultViewManager

$dts is a DataSet with 3 tables and 2 relations on primary keys.
This works but I get a useless root node for "TypesDataTemplate". I tried to plug the treeview to"StatusDataTemplate" but then nothing appear anymore.
I'm bit confused about what is happening there.

Windows for business | Windows Server | User experience | PowerShell
Developer technologies | XAML
Developer technologies | XAML

A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.