Example E2766
Visible to All Users

WinForms Data Grid - Display many-to-many Entity Framework object relationship

This example demonstrates how to use the WinForms Data Grid control to configure and visualize a many-to-many relationship of Entity Framework objects.

Files to Review

Documentation

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

Entities/Form1.cs(vb)
C#
using System; using System.Linq; using System.Data.Objects; using System.Windows.Forms; using DevExpress.XtraEditors; namespace DXSample { public partial class Form1 : XtraForm { NorthwindEntities northwind; public Form1() { InitializeComponent(); northwind = new NorthwindEntities(); ObjectQuery<Product> productsQuery = northwind.Products.Include("Order_Details.Order"); gridControl1.DataSource = new BindingSource(productsQuery, ""); } private void OnMasterRowEmpty(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowEmptyEventArgs e) { Product p = (Product)gridView1.GetRow(e.RowHandle); e.IsEmpty = p.Order_Details.Count == 0; } private void OnMasterRowGetRelationCount(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetRelationCountEventArgs e) { e.RelationCount = 1; } private void OnMasterRowGetRelationName(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetRelationNameEventArgs e) { e.RelationName = "Orders"; } private void OnMasterRowGetChildList(object sender, DevExpress.XtraGrid.Views.Grid.MasterRowGetChildListEventArgs e) { Product p = (Product)gridView1.GetRow(e.RowHandle); e.ChildList = p.Order_Details.Select(od => od.Order).Distinct().ToList(); ; } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.