0

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.

mtf
  • 329
  • 2
  • 13
  • 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 Answers2

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
  • Can you write an example in c# for this purpose, please? - @svetlana – mtf Nov 20 '18 at 12:56
  • 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