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

master-detail DataGrid's for many-to-many relationship

Thread ID:





6457 Aug 13,2003 11:57 AM UTC Aug 15,2003 04:58 PM UTC WinForms 1
Tags: FAQ
Dennis McCarthy
Asked On August 13, 2003 11:57 AM UTC

My database contains a STUDENTS table, a COURSES table, and an ENROLLMENTS table. The ENROLLMENTS table represents the many-to-many relationship between students and courses. I would like to have a master-detail pair of DataGrid's. The master grid contains students, and the detail grid contains the courses in which the selected student is enrolled. Master-detail grids are easy when there is a parent-child relationship between two tables. However, in my case the parent child relationship is between the STUDENTS and ENROLLMENTS tables (and the COURSES and ENROLLMENTS). How can I get a pair of DataGrid's to act as master-detail for this many-to-many relationship? Thanks, Dennis

Dennis McCarthy
Replied On August 15, 2003 04:58 PM UTC

Here's how I got this to work: 1) Read the STUDENTS, COURSES and ENROLLMENTS tables into a DataSet. 2) Add two DataRelations to the DataSet. One has STUDENTS as the parent and ENROLLMENTS as the child. The other has COURSES as the parent and ENROLLMENTS as the child. 3) Add computed DataColumn's to the ENROLLMENTS DataTable in the DataSet. These columns correspond to columns in the COURSES table. Their expression is along the lines of "Parent(COURSE_ENROLLMENTS).COURSE_NAME". 4) Bind the master grid to the STUDENTS DataTable in the DataSet. 5) Bind the detail grid to the ENROLLMENTS DataTable in the DataSet. It will appear as if the detail grid is bound to the COURSES table, since the ENROLLMENTS DataTable contains the COURSES columns. The master grid will display all students. The detail grid will display only the courses in which the student (row selected in the master grid) is enrolled. Dennis


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