There are 2 Objects with a relationship between them. Student and Class. Each student has one or more classes. I want to show student in a grid control (devexpress winform) and I prefer not to use master detail. I want to show classes in a single column, like : class A-class B (in a single row) or split the row like merging.
Asked
Active
Viewed 304 times
0
-
You could do this in your sql statement also, sql server has the `stuff` statement you can use to concatinate all classes per student into one column. Other databases wlll have other commands, you did not say where your data comes from – GuidoG Nov 20 '18 at 10:26
2 Answers
0
It is possible to create an unbound column to populate it with your detail data. See the How to access a detail view's data within the CustomUnboundColumnData event handler example to learn how to do this.

Svetlana
- 421
- 3
- 5
-
-
You can download the mentioned example by using the provided link above. Once you go to there, you will see the Download button. Alternatively, you can download this project directly from GitHub (https://github.com/DevExpress-Examples/how-to-access-a-detail-views-data-within-the-customunboundcolumndata-event-handler-e2442) – Svetlana Nov 20 '18 at 19:33
0
From what database is this info coming ?
If you are using Sql Server
you can merge the data in your query like this
declare @student table (studentid int, name varchar(20))
declare @class table (classid int, name varchar(20))
declare @studentclass table (studentid int, classid int)
insert into @student values (1, 'john'), (2, 'mary')
insert into @class values (1, 'english'), (2, 'mathematics')
insert into @studentclass values (1, 1), (1, 2), (2, 1)
select s.studentid,
s.name,
stuff(( replace (( select ' - ' + c.name
from @class c
inner join @studentclass sc on c.classid = sc.classid
where sc.studentid = s.studentid
order by c.name
For XML PATH ('')), '', '')
), 1, 3, '') as classes
from @student s
This will return this result :
studentid name classes
--------- ---- -------
1 john english - mathematics
2 mary english
Other databases can do this also, the syntax will be different off course

GuidoG
- 11,359
- 6
- 44
- 79
-
-
Well no ORM tool will do this for you, thats why you have to do sql sometimes – GuidoG Nov 20 '18 at 12:38
-
-
Maybe, I havent got this working in `linq` yet but im no expert in that – GuidoG Nov 20 '18 at 13:19