mtf
mtf

Reputation: 329

Display relationship in a devexpress grid

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.

Upvotes: 0

Views: 364

Answers (2)

GuidoG
GuidoG

Reputation: 12014

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

Upvotes: 0

Svetlana
Svetlana

Reputation: 421

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.

Upvotes: 0

Related Questions