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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Display relationship between grid table

Thread ID:

Created:

Updated:

Platform:

Replies:

143869 Apr 8,2019 03:20 PM UTC Apr 10,2019 12:18 PM UTC WinForms 5
loading
Tags: SfDataGrid
Alan Oliveira
Asked On April 8, 2019 03:20 PM UTC

I have a situation and I can not solve it.
The following is. I have two entities "Protutos and Categories", with relationship between them.
In the attribute of Protutos has Category related to table categories. How do I display this category in Product GRID, tried several more unsuccessful ways.

Jagadeesan Pichaimuthu [Syncfusion]
Replied On April 9, 2019 01:07 PM UTC

Hi Alan, 

Thanks for using Syncfusion products. 

If you want to create the relational data grid, you can use the following UG link and the DB sample. 

UG Link: 
 
Sample: 
<InstalledLocation>/Windows/DataGrid.WinForms/Samples/DetailsViewDataTableBinding  

If we misunderstood your requirement, please provide more information regarding the requirement. This would help us to proceed further. 

Regards, 
Jagadeesan 


Alan Oliveira
Replied On April 9, 2019 10:41 PM UTC

Hello,

Let me explain better. Below I have my model with Category and Product, I want to display the category name that is related to the product on my grid without the need to use "masterdetailsview". Below is the grid example of how I want to show in sfdatagrid.

Example GRID:



MODEL:


Jagadeesan Pichaimuthu [Syncfusion]
Replied On April 10, 2019 07:26 AM UTC

Hi Alan, 

Thanks for using Syncfusion product. 

Your requirement can be achieved by setting AutoGeneratedColumns to false and adding the columns manually with below code. Here to add the child class property in column name mention like “Category.CategoryName”. 

sfDataGrid1.AutoGenerateColumns = false; 
sfDataGrid1.DataSource = GetCollection(); 
 
sfDataGrid1.Columns.Add(new GridNumericColumn() { MappingName = "ProductID" }); 
sfDataGrid1.Columns.Add(new GridTextColumn() { MappingName = "ProductName" }); 
sfDataGrid1.Columns.Add(new GridTextColumn() { MappingName = "Category.CategoryName" }); 
sfDataGrid1.Columns.Add(new GridNumericColumn() { MappingName = "UnitPrice" }); 
sfDataGrid1.Columns.Add(new GridTextColumn() { MappingName = "Status" }); 


Please find the sample from below location, 


 

If we misunderstood your requirement, please provide more information regarding the requirement. This would help us to proceed further. 

Regards, 
Jagadeesan

Alan Oliveira
Replied On April 10, 2019 11:09 AM UTC

Hi Jagadeesan,

I ran the tests that way and it worked.
But I'd like to know there is another way using "sfDataGrid1.AutoGenerateColumns = TRUE;".
In my project AutoGenerateColumns is enabled, I control the model using "[Display (Name =" ProductID ", Order = 0)]"

Jagadeesan Pichaimuthu [Syncfusion]
Replied On April 10, 2019 12:18 PM UTC

Hi Alan, 
 
Thanks for your update. 
 
Your requirement can be achieved by enable the AutoGenerateColumnsForCustomType and properly define the inner class properties as like the below code snippet. 
 
sfDataGrid1.AutoGenerateColumnsForCustomType = true; 
 
public class Category 
{ 
    [Bindable(false)] 
    public int CategoryID { get; set; } 
 
    [Display(Name = " CategoryName ", Order = 0)] 
    public string CategoryName { get; set; } 
 
 
    public IList<Product> Products { get; set; } 
} 
 
Please refer the modified sample from below, 
 
Let us know whether this helps also if you need any further assistance on this. 
 
Regards, 
Jagadeesan

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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon