This is a migrated thread and some comments may be shown as answers.

Grouping and Sorting

2 Answers 218 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 05 Oct 2010, 04:42 PM

How can you group off one column but sort on another column through code??

I have one column that has the group name "string" lets say 'ROOM' but the order they need to be displayed is an int lets say "Room Order" so I have data like

Bedroom, 2,  'Some Info1'
Bedroom, 2,  'Some Info2'
Bedroom, 2,  'Some Info3'
Kitchen, 1, 'Some Info1'
Kitchen, 1, 'Some Info2'
Kitchen, 1, 'Some Info3'
Bathroom, 3, 'Some Info1'
Bathroom, 3, 'Some Info2'

I want to group off of the ROOM column but sort offer the Room Order column, however, once I group it always sorts off the group column, in this example ROOM

I have tried bringing in the data already sorted it does help. I have also tried following code:

Me

 

.gvRoomNights.Columns("ROOM_SORT_ORDER_SITE").Sort(RadSortOrder.Ascending, True)

 

 

 

Dim expression As New GridGroupByExpression("[ROOM_POOL_CD] as [Room Pool] Group By [Room Pool]")

 

 

'Dim expression2 As New GridSortField("[ROOM_SORT_ORDER_SITE]")

 

gvRoomNights.EnableSorting =

True

 

gvRoomNights.MasterTemplate.EnableSorting =

True

 

gvRoomNights.MasterTemplate.GroupDescriptors.Add(expression)

 

Me.gvRoomNights.Columns("ROOM_SORT_ORDER_SITE").Sort(RadSortOrder.Ascending, True)

 

 

'gvRoomNights.MasterTemplate.SortDescriptors.Add(expression2)

 

gvRoomNights.Columns(

"ROOM_POOL_CD").Width = 60

I guess I could group by the ROOM SORT ORDER but I need to change the Groups HEader text to the actual room name. If you can show me that I would be able to get around this. Thanks.

 


Eric

2 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 05 Oct 2010, 05:16 PM
Hi Eric, 

You are right to enable grouping and sorting. After populating the Grid, try this

' Clear the current groups
Me.GridView.GroupDescriptors.Clear()
' Declare a new Group By Expression
Dim expression As New GridGroupByExpression()
expression.Expression = "GroupByColumnName as Alias Group By Alias"
' Add the group descriptor
GridView.MasterTemplate.GroupDescriptors.Add(expression)
' Clear current sorting
Me.GridView.SortDescriptors.Clear()
' Add your new sort descriptor
Me.GridView.SortDescriptors.Add("SortByColumn", System.ComponentModel.ListSortDirection.Descending)

hope that helps
Richard
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 05 Oct 2010, 05:26 PM
Hello Eric,

And as an added point to Richards solution, if you want to change the Group Header text you should use GroupSummaryEvaluate event to format the displayed text according to your particular needs. Please find out how to do that in Formatting Group Header Row documentation.

Let me know if you have any other questions.

Best Regards,
Emanuel Varga
Tags
GridView
Asked by
Eric
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Emanuel Varga
Top achievements
Rank 1
Share this question
or