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. Image for the cookie policy date
close icon

Need some help with foreign key references and values

Hi
I have a table that I has the key values in it but I want to reference data from another table with that key and there are multiple key values in table 1
So table has for instance
Client - transaction - bank
1 - 20/9/2015 - 2
the 1 and 2 I want to replace with the data in the other 2 tables
Client - transaction - bank
John - 20/9/2015 - HSBC

how can I do this I tried finding the solution in the documentation but I can not find what I am looking for

thank you


7 Replies

AK Adhikesevan Kothandaraman Syncfusion Team September 22, 2015 12:59 PM UTC

Hi Pierre,

Thanks for your update.

To have a foreign key relation in GridGroupingControl, you need to add the GridRelationDescriptor to the table descriptor and set the RelationKind as ForeignKeyReference. Please refer to the following code example,

Code Example:

GridTableDescriptor mainTd = this.gridGroupingControl1.TableDescriptor;

GridRelationDescriptor usStatesRd = new GridRelationDescriptor();

usStatesRd.Name = "State";

usStatesRd.RelationKind = RelationKind.ForeignKeyReference;

usStatesRd.ChildTableName = "USStates";  // SourceListSet name for lookup
usStatesRd.RelationKeys.Add("State", "Key");
mainTd.Relations.Add(usStatesRd);

Please refer to the following Dashboard sample, in which we have adding the foreign key reference to the GridGroupingControl.

Sample Location:
<InstalledLocation>\Syncfusion\EssentialStudio\<VersionNo>\Windows\Grid.Grouping.Windows\Samples\Relation And Hierarchy\Foreign-Key Reference Demo\CS

Regards,
Adhi



PS Pierre Smith October 14, 2015 09:23 AM UTC

Hi Adhi

I made some changes to my database . I am using Entity Framework and the table that I am using have child tables so it gets loaded automatically when I bind to that table. Now I just want to know how do I make my Child tables show up as Dropdown boxes so that the client can select them

Regards


SA Solai A L Syncfusion Team October 16, 2015 01:38 AM UTC

Hi Pierre,

You can use QuerCellStyleInfo event to add a dropdown to child table cells. Please refer the code example and let us know if you have any other concerns.

Code example:

this.groupingGrid1.QueryCellStyleInfo += new GridTableCellStyleInfoEventHandler(groupingGrid1_QueryCellStyleInfo);

void groupingGrid1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e)

        {

            if (e.TableCellIdentity.TableCellType == GridTableCellType.EmptySectionRowHeaderCell)//check the celltype of your child table and set the condition accordingly.

                e.Style.CellType = GridCellTypeName.ComboBox;

                e.Style.DataSource = list;

        }

Regards,
AL.Solai.



PS Pierre Smith November 9, 2015 05:34 AM UTC

HI Al

First of this is done at runtime is there no option for design time where you can change the options to a dropdownbox and set the data source
then in the example you gave me what type of source can I use . Only a list or can do i need to use the same table as the data source and how do i bring the same table in to the source

Regards



AG Anish George Syncfusion Team November 10, 2015 04:00 PM UTC


Hi Pierre,

It is not possible to access the dropdown box in GridControl while in design mode. The values can be assigned only in runtime. And the data source assigned in the combo box can be a list or of any type.

We are not quite clear with the query “how do i bring the same table in to the source”? We assume that you are asking, whether it is possible to use the same data source of the GridGroupingControl to the Dropdownbox? In that case it is possible to add the same datasource to the dropdownbox.

Please let us know whether we have misunderstood your query.

Regards,
Anish



PS Pierre Smith November 18, 2015 08:46 AM UTC

Hi Anish

This is my situation . My main table has a few key references to other tables and with entity framework those tables now get pulled into the grid so you get the situation of
Key-Int , Value , Value , Key Table2 , Table2 value

so if i want to change table2 value in the grid I need to specify the Key table 2 manually. I want Key table 2 to reference the other table values with a drop down box but seeing as the table is being pulled into the grid via entity framework i was thinking of using that info

Regards
Pierre


AG Anish George Syncfusion Team November 19, 2015 04:57 PM UTC

Hi Pierrre,

Sorry for the inconvenience caused.

We are quite unclear on what you are trying to achieve. I assume that you are trying to access an entity datasource into the dropdownbox which is not possible. Could you please modify the below sample which has an entity framework as datasource so that we can suggest you solution. Or you can create an incident through your Direc Trac mail ID given so that our dedicated engineers can assist you and can give you a quick solution.

Sample:
http://www.syncfusion.com/downloads/support/directtrac/general/ze/CS1194095274.zip        

Regards,
Anish

Loader.
Live Chat Icon For mobile
Up arrow icon