Thanks for your solution, Grafix. It is very nice. I thought it would be neater to place it in a Converter, so I did it like this:
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var abList = value as List<AB>;
if (abList == null)
return null;
var retVal = Enum.GetValues(typeof (MyEnumB)).Cast<MyEnumB>().Select(
b =>
new ABViewModel()
{
Name = b,
OptionA1 = abList.Any(ab => ab.B == b && ab.A == MyEnumA.OptionA1),
OptionA2 = abList.Any(ab => ab.B == b && ab.A == MyEnumA.OptionA2),
OptionA3 = abList.Any(ab => ab.B == b && ab.A == MyEnumA.OptionA3)
}).ToList();
return retVal;
}
And the DataGrid:
<DataGrid Height="215" HorizontalAlignment="Left" Margin="91,12,0,0" Name="dataGrid1"
VerticalAlignment="Top" Width="299"
ItemsSource="{Binding ABList, Converter={StaticResource listToDataTableConverter}}"
d:DataContext="{d:DesignData }" />
And I set the DataContext like this:
public MainWindow()
{
InitializeComponent();
ABList.Add(new AB { A = MyEnumA.OptionA2, B = MyEnumB.OptionB1 });
ABList.Add(new AB { A = MyEnumA.OptionA3, B = MyEnumB.OptionB3 });
DataContext = this;
}