Hi Igor
for displaying you can use readonly ComboBoxColumn like in following demo:
XAML:
<Window x:Class="WpfApp1.Window018"
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:WpfApp018"
mc:Ignorable="d"
Title="Window018" Height="450" Width="800">
<Window.Resources>
<local:ViewModel x:Key="vm"/>
</Window.Resources>
<Grid DataContext="{StaticResource vm}">
<DataGrid ItemsSource="{Binding Persons}" AutoGenerateColumns="false">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding PersonId}"/>
<DataGridTextColumn Header="Firstname" Binding="{Binding FirstName}"/>
<DataGridComboBoxColumn Header="Role name"
IsReadOnly="True"
ItemsSource="{Binding Roles, Source={StaticResource vm}}"
SelectedValueBinding="{Binding RoleId}"
SelectedValuePath="RoleId"
DisplayMemberPath="RoleName"/>
</DataGrid.Columns>
</DataGrid>
</Grid>
</Window>
Classes:
using System;
using System.Collections.Generic;
using System.Windows;
namespace WpfApp018
{
public class ViewModel
{
public ViewModel()
{
Random rnd = new Random();
for (int i = 1; i < 10; i++) colPersons.Add(new Person() { PersonId = i, FirstName = $"First name {i}", RoleId = rnd.Next(1, 5) });
colRoles.Add(new Role() { RoleId = 1, RoleName = "Admin" });
colRoles.Add(new Role() { RoleId = 2, RoleName = "User" });
colRoles.Add(new Role() { RoleId = 3, RoleName = "Member" });
colRoles.Add(new Role() { RoleId = 4, RoleName = "Owner" });
}
private List<Person> colPersons = new List<Person>();
private List<Role> colRoles = new List<Role>();
public List<Person> Persons { get => colPersons; }
public List<Role> Roles { get => colRoles; }
}
public class Person
{
public int PersonId { get; set; }
public string FirstName { get; set; }
public int RoleId { get; set; }
}
public class Role
{
public int RoleId { get; set; }
public string RoleName { get; set; }
}
}
Result: