Hi Lloyd,
your code works fine. Try following demo:
XAML MainWindow
<Window x:Class="WpfApp1.Window009"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp009"
mc:Ignorable="d"
Title="Window009" Height="450" Width="800">
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TreeView ItemsSource="{Binding View}">
<TreeView.Resources>
<HierarchicalDataTemplate DataType="{x:Type local:SeasonList}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontSize="16" FontWeight="Bold" Margin="5"/>
<TextBlock Text="Season: " FontSize="16" FontWeight="Bold" Margin="5"/>
<ComboBox ItemsSource="{Binding Season}"
SelectedItem="{Binding selectedSeason}"
SelectedIndex="{Binding selectedIndex}"
Width="100"/>
</StackPanel>
</HierarchicalDataTemplate>
</TreeView.Resources>
</TreeView>
<DataGrid Grid.Row="1" ItemsSource="{Binding View}" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
<DataGridTextColumn Header="selectedSeason" Binding="{Binding selectedSeason}"/>
<DataGridTextColumn Header="selectedIndex" Binding="{Binding selectedIndex}"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
And classes:
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Data;
namespace WpfApp009
{
public class ViewModel
{
public ViewModel()
{
for (int i = 1; i < 10; i++)
{
col.Add(new SeasonList()
{
Name = $"Node {i}",
Season =
new ObservableCollection<string>(new string[] { "Spring", "Summer", "Autumn", "Winter" })
});
}
cvs.Source = col;
}
public ICollectionView View { get => cvs.View; }
private CollectionViewSource cvs = new CollectionViewSource();
private ObservableCollection<SeasonList> col = new ObservableCollection<SeasonList>();
}
public class SeasonList
{
public string Name { get; set; }
public ObservableCollection<string> Season { get; set; } = new ObservableCollection<string>();
public string selectedSeason { get; set; }
public int selectedIndex { get; set; }
}
}
Result: