0

This is what I have:

ObservableCollection<Item>()

ObservableCollection<Group> Groups = new ObservableCollection<Group>()

Each Group have a key, a name, a subgroup with the type ObservableCollection<Group>() and a itemList with type ObservableCollection<Item>().

My Treeview in the main window looks like this:

<TreeView Name="treeViewGroup" BorderThickness="0,2,0,0" ItemsSource="{Binding}">
<TreeView.Resources>
    <HierarchicalDataTemplate DataType="{x:Type data:Group}" ItemsSource="{Binding Items}">
        <StackPanel>
            <TextBlock Text="{Binding Path=Name}" />
        </StackPanel>
    </HierarchicalDataTemplate>

    <DataTemplate DataType="{x:Type data:ItemCollection}" >
        //<StackPanel >
        //  <test:ucTable x:Name="table1" DataContext="{Binding IpAdress}">
        //      <TextBlock Text="{Binding Path=Name}" />
        //  </test:ucTable>
        //</StackPanel>
    </DataTemplate>
</TreeView.Resources>

The uc with the table looks like this:

<UserControl x:Class="namespace.GUI.ucTable"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         x:Name="ucTable"
         mc:Ignorable="d" 
         d:DesignHeight="200" d:DesignWidth="500" >

<DataGrid x:Name="table1" Margin="10,10,10,10"
            AutoGenerateColumns="False" CanUserAddRows="False" 
            CanUserReorderColumns="False" CanUserResizeRows="False" CanUserResizeColumns="False" 
            AlternatingRowBackground="AliceBlue" Grid.IsSharedSizeScope="True">

  <DataGrid.ContextMenu>
    <ContextMenu>
      <MenuItem Header="Information"/>
      <MenuItem Header="Delete"/>
    </ContextMenu>
  </DataGrid.ContextMenu>

  <DataGrid.Columns>
    <DataGridTextColumn Header="Name" Binding="{Binding Name, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Width="Auto" />
    <DataGridTextColumn Header="Location" Binding="{Binding Location, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Width="Auto" />
    <DataGridTextColumn Header="Ip" Binding="{Binding IpAdress, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Width="Auto" IsReadOnly="True" />

  </DataGrid.Columns>
</DataGrid>

What I would like to have is a Treeview with all nested groups and if a group has a itemList with items the items should be in the usercontrol in the datagrid.

I tried a lot of examples and stuff but it doesn't work. Have someone an idea?

Thanks in advance

Ramankingdom
  • 1,478
  • 2
  • 12
  • 17
PMe
  • 545
  • 2
  • 9
  • 20
  • So you want to Show Tree Nodes as Group and Group Items in a Grid which will show on expand of nodes Is it? – Ramankingdom Aug 01 '17 at 09:07
  • Yes that what I need. – PMe Aug 01 '17 at 09:24
  • I would like to suggest you Use two things First DataTemplateSelector . if it is the top node show normal text. If it has child Show DataGridTemplate. This is tricky. So start step by step. First show all hierarchical data and then next – Ramankingdom Aug 01 '17 at 10:13
  • I created on screen is that is your requirement. https://pasteboard.co/GDTRoBr.png – Ramankingdom Aug 03 '17 at 06:33

0 Answers0