Display relationship between grid table
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.
SIGN IN To post a reply.
5 Replies
JP
Jagadeesan Pichaimuthu
Syncfusion Team
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
AO
Alan Oliveira
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:
JP
Jagadeesan Pichaimuthu
Syncfusion Team
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
AO
Alan Oliveira
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)]"
JP
Jagadeesan Pichaimuthu
Syncfusion Team
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,
Sample : http://www.syncfusion.com/downloads/support/forum/143869/ze/DataTable_Sample_Modified1776481624
Let us know whether this helps also if you need any further assistance on this.
Regards,
Jagadeesan
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
-
AO Alan Oliveira
- Apr 8, 2019 03:20 PM UTC
- Apr 10, 2019 12:18 PM UTC