I've been trying to code my grid to allow a user to choose a job to assign a list of materials to.
There is a Material table which is bound to the data grid. It has a foreign key link to the Job table.
I initially bound the Material.Job field but due to the fact that it has a foreign key constraint underneath in Linq2Sql, whenever the grid tried to update the value it would fire the exception 'ForeignKeyReferenceAlreadyHasValueException'.
Linq has given me a Job1 field which gives me entity access to set it to an existing Job #. So I've tried creating a ForeignKeyConfiguration for this field, and I can get it to display the jobs I want in the ComboBox but it won't then assign the selected Job to the Material.Job1 property. I'm banging my head against a wall here 
Here are some code snippets that might help illustrate what I having been trying to explain.
My DataGridCollectionViewSources:
<DockPanel>
<DockPanel.Resources>
<xcdg:DataGridCollectionViewSource x:Key="cvs_materials" Source="{Binding Path=Materials}"
DefaultCalculateDistinctValues="False"
AutoCreateDetailDescriptions="True"
AutoCreateItemProperties="True"
AutoCreateForeignKeyDescriptions="True">
</xcdg:DataGridCollectionViewSource>
<xcdg:DataGridCollectionViewSource x:Key="cvs_jobs" Source="{Binding Path=Jobs}"
DefaultCalculateDistinctValues="False"
AutoCreateDetailDescriptions="True"
AutoCreateItemProperties="True"
AutoCreateForeignKeyDescriptions="True">
</xcdg:DataGridCollectionViewSource>
</DockPanel.Resources>
My Page class:
public partial class ViewNewMaterialsPage : Page
{
private X1BCSdb db = new X1BCSdb();
private IQueryable<Material> materials;
private IQueryable<Job> jobs;
public IQueryable<Material> Materials {
get { return materials; }
set { if (value != null) materials = value; }
}
public IQueryable<Job> Jobs {
get { return jobs; }
set { if (value != null) jobs = value; }
}
public ViewNewMaterialsPage()
{
// All materials that aren't already assigned to a job
materials = from m in db.Materials
where !m.Job.HasValue
select m;
jobs = from Job j in db.Jobs
where !(j.Cancelled) // or delivered?
select j;
InitializeComponent();
}
private void Page_Initialized(object sender, EventArgs e)
{
this.DataContext = this;
}
My XAML for the two fields of interest:
<xcdg:DataGridControl ItemsSource="{Binding Source={StaticResource cvs_materials}}" Name="NewMaterialsDataGrid" Loaded="NewMaterialsDataGrid_Loaded"
NavigationBehavior="RowOrCell"
CellEditorDisplayConditions="CellIsCurrent" UpdateSourceTrigger="CellEndingEdit" ReadOnly="False"
AutoCreateColumns="False" AutoCreateDetailConfigurations="False"
AutoCreateForeignKeyConfigurations="True" >
<xcdg:DataGridControl.Resources>
<Style x:Key="{x:Type xcdg:ScrollTip}" TargetType="xcdg:ScrollTip">
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="VerticalAlignment" Value="Center" />
</Style>
</xcdg:DataGridControl.Resources>
<xcdg:DataGridControl.View>
<xcdg:TableView ShowFixedColumnSplitter="False" UseDefaultHeadersFooters="False" ShowScrollTip="True">
<xcdg:TableView.FixedHeaders>
<DataTemplate>
<xcdg:HierarchicalGroupByControl xcdg:TableView.CanScrollHorizontally="False" />
</DataTemplate>
<DataTemplate>
<xcdg:ColumnManagerRow AllowAutoFilter="False" />
</DataTemplate>
</xcdg:TableView.FixedHeaders>
</xcdg:TableView>
</xcdg:DataGridControl.View>
<xcdg:DataGridControl.Columns>
<xcdg:Column FieldName="ProwosNo" Title="Prowos #" IsMainColumn="True" ReadOnly="True" />
<xcdg:Column FieldName="PickingSlipNo" IsMainColumn="False" Title="Picking Slip #" ReadOnly="True" />
<xcdg:Column FieldName="LineNo" Title="Line #" ReadOnly="True" />
<xcdg:Column FieldName="OrderNumber" Title="Keyed Order #" ReadOnly="True" />
<xcdg:Column FieldName="Job" Title="Job #" ReadOnly="False" >
<xcdg:Column.DisplayMemberBindingInfo>
<xcdg:DataGridBindingInfo Path="Job">
<xcdg:DataGridBindingInfo.ValidationRules>
<local:JobValidationRule ValidationStep="ConvertedProposedValue" />
</xcdg:DataGridBindingInfo.ValidationRules>
</xcdg:DataGridBindingInfo>
</xcdg:Column.DisplayMemberBindingInfo>
<xcdg:Column.CellEditor>
<xcdg:CellEditor>
<xcdg:CellEditor.EditTemplate>
<DataTemplate>
<xcdg:NumericTextBox ValueDataType="{x:Type s:Int32}" Value="{xcdg:CellEditorBinding}" />
</DataTemplate>
</xcdg:CellEditor.EditTemplate>
</xcdg:CellEditor>
</xcdg:Column.CellEditor>
</xcdg:Column>
<xcdg:Column FieldName="Job1" Title="Job # 2" ReadOnly="False" >
<xcdg:Column.ForeignKeyConfiguration>
<xcdg:ForeignKeyConfiguration ItemsSource="{Binding Source={StaticResource cvs_jobs}}"
DisplayMemberPath="JobID" >
</xcdg:ForeignKeyConfiguration>
</xcdg:Column.ForeignKeyConfiguration>
</xcdg:Column>
At the moment the Job # 2 column shows the ComboBox and lists the valid Jobs, but when I select one it doesn't seem to get assigned to the Job1 field. Do I need to define a CellContentTemplate also?