I have searched all over and keep finding similar examples that are not working for me. Can someone point out where I am messing up?
I have two tables AlarmName and AlarmLevel. Linked by a foreign key AlarmName.AlarmLevelID -> AlarmLevel.Id.
I have the following in my XAML:
<DataGrid Name="Alarms" AutoGenerateColumns="false">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Name}" Header="Name" Width="75" />
<DataGridTextColumn Binding="{Binding Description}" Header="Description" />
<DataGridTextColumn Binding="{Binding AlarmLevel.Name}" Header="AName" Width="75"/>
<DataGridTemplateColumn Header="Alarm Level">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding DataContext.AlarmLevel, RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}}"
DisplayMemberPath="Name"
SelectedValuePath="AlarmLevelID"
SelectedValue="{Binding Id}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
And the following in my code behind:
UISimulation1.Data.UISimulationDBDataContext db = new UISimulation1.Data.UISimulationDBDataContext();
var alarm = (from v in db.AlarmNames
select v);
Alarms.ItemsSource = alarm;
The DataGridTextColumns work and pull the right data. However, I can not make the combobox work or display anything no matter what I try.
Clearly, I am missing something obvious; but have tried 50 variants of the combobox based on google examples with zero results.
--rt