When I hit an issue, sometimes I like to remove the noise and break out a small project that focuses on the main issue. I have done just that for you.
Start a new WPF project with the name
WpfDataGridComboBox
and drop this code in and you can see how it works.
1.
MainWindow.xaml
<Window x:Class="WpfDataGridComboBox.MainWindow"
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"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"
x:Name="Window1">
<Grid DataContext="{Binding ElementName=Window1}">
<Grid.Resources>
<CollectionViewSource x:Key="ChoicesCVS"
Source="{Binding Choices}" />
</Grid.Resources>
<DataGrid AutoGenerateColumns="False"
ItemsSource="{Binding Items}">
<DataGrid.Columns>
<DataGridTextColumn Header="Name"
Binding="{Binding Name}" />
<DataGridTextColumn Header="Age"
Binding="{Binding Age}" />
<DataGridComboBoxColumn
Header="Mode" Width="100"
SelectedItemBinding="{Binding Choice}"
ItemsSource="{Binding Source={StaticResource ChoicesCVS}}">
</DataGridComboBoxColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
2. the code behind file
MainWindow.xaml.cs
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Windows;
namespace WpfDataGridComboBox
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public List<string> Choices { get; set; } = new()
{
"Choice 1",
"Choice 2",
"Choice 3"
};
public ObservableCollection<Person> Items { get; set; } = new()
{
new() { Name = "Freddie", Age = 21, Choice = "Choice 1" },
new() { Name = "Milly", Age = 18, Choice = "Choice 2" },
new() { Name = "Caddie", Age = 23, Choice = "Choice 3" },
};
}
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public string Choice { get; set; }
}
}
Now run the project and it will perform as expected. Now you can take this and apply to your own code.