We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

GridComboBoxColumn bound to DataTable, Primary Key inserted as Foreign Key in Parent DataTable

Thread ID:

Created:

Updated:

Platform:

Replies:

124420 Jun 8,2016 02:55 PM UTC Jun 9,2016 09:25 AM UTC WPF 2
loading
Tags: SfDataGrid
James
Asked On June 8, 2016 02:55 PM UTC

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:
  1. Will populate its list from  DataTable dtList, and display in the dropdown the strings Country (not its Primary Key L_ID)
  2. 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 
  1. FTELOCComboBox is bound in code behind to: FTELOCComboBox.ItemsSource = ViewModel.FTE_LocationDataTable;
  2. And ViewModel.FTE_LocationDataTable is  public DataTable FTE_LocationDataTable {get { return _FTE_Location; }} and _FTE_Location is a DataTable
  3. 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


James
Replied On 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. 


Jai Ganesh S [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;