Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I want to know how can I make a programaticly sort, I found the bellow example
from the bellow link: http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/49ed286b-5aea-4414-b58a-9f10601eb076[^]
SortFields sortFields = m_Report.DataDefinition.SortFields;
sortFields[0].Field = m_Report.Database.Tables[table].Fields[field];
sortFields[0].SortDirection = CrystalDecisions.Shared.SortDirection.AscendingOrder;


The problem that I have three sort parameter,(Sub_id,Gender and JobCateg), that example don't work with it,

Thanks in Advance
Otto
Posted
Updated 19-Jun-11 19:48pm
v3

OP wrote:
I found the bellow example
from the bellow link: http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/49ed286b-5aea-4414-b58a-9f10601eb076[^]

Sadly it's not a solution link, there also the OP asked the question like you.
Don't worry I'll give you solution.

Here you go
C#: Adding many SortField to a CrystalReportViewer using reflection[^]

OP wrote:
thanks in advance
Otto

Off Topic, Recently I saw the movie Lovers of the Arctic Circle[^], In that, the leading character name also Otto which is palindrome :)
 
Share this answer
 
thanks a lot for your answer, i will try it, and back to you asap.

Otto :)
 
Share this answer
 
VB
Hello, It is working fine

Dim fieldDef As DatabaseFieldDefinition = ReportDoc.Database.Tables(crTable.Name).Fields(crField.Name)
getRasSorts = targetSortField.[GetType]().GetMethod("get_RasSorts", BindingFlags.NonPublic Or BindingFlags.Instance)
rasSorts = getRasSorts.Invoke(targetSortField, System.Type.EmptyTypes)
addSort = rasSorts.[GetType]().GetMethod("Add")
rasAssembly = getRasSorts.ReturnType.Assembly
ciRasSort = rasAssembly.[GetType]("CrystalDecisions.ReportAppServer.DataDefModel.SortClass").GetConstructor(BindingFlags.[Public] Or BindingFlags.Instance, Nothing, System.Type.EmptyTypes, Nothing)
rasSort = ciRasSort.Invoke(System.Type.EmptyTypes)
setSortField = rasSort.[GetType]().GetMethod("set_SortField", BindingFlags.[Public] Or BindingFlags.Instance)
Dim getRasField As MethodInfo = fieldDef.[GetType]().GetMethod("get_RasField", BindingFlags.NonPublic Or BindingFlags.Instance)
Dim rasField As Object = getRasField.Invoke(fieldDef, System.Type.EmptyTypes)
addSort.Invoke(rasSorts, New Object() {rasSort})
setSortField.Invoke(rasSorts, New Object() {rasField})
Dim n As Integer = ReportDoc.DataDefinition.SortFields.Count - 1
targetSortField(n).Field = fieldDef
targetSortField(n).SortDirection = CrystalDecisions.[Shared].SortDirection.AscendingOrder
 
Share this answer
 
v2
Comments
CHill60 27-Jan-14 8:30am    
Only one problem really ... the OP wanted C# ... oh and it was over 2 years ago
SQL
I found this problem now and it cost me a lot of time to fix it. I just wanted to leave the solution in case someone has to go back.

I think that pass it to c # not is very difficult
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900