Диаграмма БД
Создал приложение, которое позволяет редактировать таблицу User при помощи Datagrid и сохранять результат.
MainWindow.xaml
<Window
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:Test"
mc:Ignorable="d" x:Class="Test.MainWindow"
Title="Test" Height="350" Width="525" Loaded="Window_Loaded" Closing="Window_Closing">
<Window.Resources>
<CollectionViewSource x:Key="typeViewSource"
d:DesignSource="{d:DesignInstance {x:Type local:Type}, CreateList=True}" />
<CollectionViewSource x:Key="userViewSource"
d:DesignSource="{d:DesignInstance {x:Type local:User}, CreateList=True}" />
</Window.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<DataGrid DataContext="{StaticResource userViewSource}" Grid.Row="0" AutoGenerateColumns="False"
EnableRowVirtualization="True" ItemsSource="{Binding}"
RowDetailsVisibilityMode="VisibleWhenSelected">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding ID}" Header="ID" Width="SizeToHeader" />
<DataGridTextColumn Binding="{Binding Name}" Header="Type" Width="SizeToHeader" />
<DataGridTemplateColumn Header="Тип" Width="Auto">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox
DisplayMemberPath="Description"
ItemsSource="{Binding Source={StaticResource typeViewSource}}"
SelectedValue="ID"
SelectedValuePath="{Binding Path=ID_Type}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<Button Grid.Row="1" Content="Save" Click="Save_Click" />
</Grid>
</Window>
MainWindow.xaml.cs
using System.ComponentModel;
using System.Data.Entity;
using System.Windows;
using System.Windows.Data;
namespace Test
{
public partial class MainWindow
{
private TESTEntities _testEntitiesCnt;
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
_testEntitiesCnt = new TESTEntities();
var typeViewSource = ((CollectionViewSource) (FindResource("typeViewSource")));
_testEntitiesCnt.Type.Load();
typeViewSource.Source = _testEntitiesCnt.Type.Local;
var usersViewSource = ((CollectionViewSource) (FindResource("userViewSource")));
_testEntitiesCnt.User.Load();
usersViewSource.Source = _testEntitiesCnt.User.Local;
}
private void Save_Click(object sender, RoutedEventArgs e)
{
_testEntitiesCnt.SaveChanges();
}
private void Window_Closing(object sender, CancelEventArgs e)
{
_testEntitiesCnt.Dispose();
}
}
}
Проблема в том, что при выборе значения в колонке "тип" меняются выбранные значение во всех combobox, а не только в одном. Как можно привязать к колонке выпадающий список из которого можно было бы выбрать тип для каждого пользователя?