GridComboBoxColumn bound to DataTable, Primary Key inserted as Foreign Key in Parent DataTable
GridComboBoxColumn bound to DataTable, Primary Key inserted as Foreign Key in Parent DataTable
This took me over 10 hours to get working. This post is not a request for help, it is to document what I did should any other travelers come looking for the same soluiton
Requirement
If I have a DataTable dtList that has two columns
- L_ID as Primary Key
- Country as string
And if I have a datatable dtMaster that has a foreign key relationship to dtList with columns as below:
- ID as primary key
- L_ID as foreign key of DataTable dtList, (defined above)
I wish to create a GridComboBoxColumn that:
- Will populate its list from DataTable dtList, and display in the dropdown the strings Country (not its Primary Key L_ID)
- When the user selects a country, the combobox then takes the L_ID as selected value and inserts that foreign key L_ID into DataTable dtMaster
XAML
<syncfusion:SfDataGrid x:Name="productDataGrid"
AllowEditing="True"
AutoGenerateColumns="False"
ColumnSizer="Auto"
ItemsSource="{Binding DTMaster}"
ShowGroupDropArea="True">
<syncfusion:GridComboBoxColumn
x:Name="FTELOCComboBox" //See note below
DisplayMemberPath="Country"
HeaderText="MyHeaderText"
MappingName="L_ID"
SelectedValuePath="L_ID" />
Where
- FTELOCComboBox is bound in code behind to: FTELOCComboBox.ItemsSource = ViewModel.FTE_LocationDataTable;
- And ViewModel.FTE_LocationDataTable is public DataTable FTE_LocationDataTable {get { return _FTE_Location; }} and _FTE_Location is a DataTable
- The binding ItemsSource="{Binding dtMaster}" is the property public DataTable DTMaster { get { return dtMaster; }} where dtMaster is a DataTable
Trap
The trap that cost me hours is that I bound to the DefaultView of the datatable FTELOCComboBox.ItemsSource=ViewModel.FTE_LocatationDataTable.DefaultView
It seemed natural to bind to DefaultView, for displaying a DataTable in a grid, as this is what is mostly done. I didn't suspect it as the cause of this whole thing not working causing well over 10 hours of mucking around.
James
SIGN IN To post a reply.
2 Replies
JA
James
June 8, 2016 03:03 PM UTC
James here again, my apologies in the above post I accidentally changed the name of the DataTable dtList in the 'Requirements' to _FTE_Locatation in the code. These are the same. I wish I could edit my original post.
JG
Jai Ganesh S
Syncfusion Team
June 9, 2016 09:25 AM UTC
Hi James,
Thank you for the update. Please let us know if you need any other assistance
Regards,
Jai Ganesh S
SIGN IN To post a reply.
- 2 Replies
- 2 Participants
-
JA James
- Jun 8, 2016 02:55 PM UTC
- Jun 9, 2016 09:25 AM UTC