Crystal Reports -> Sorting Data
-
Hello, I am a newbie in Crystal Reports. I need to sort the report based on the column that the user sets in the windows form. How do I do it? I've been googling with virtually no help :( Thanks in advance. Regards, Zishan
-
Hello, I am a newbie in Crystal Reports. I need to sort the report based on the column that the user sets in the windows form. How do I do it? I've been googling with virtually no help :( Thanks in advance. Regards, Zishan
-
I don't think you can tell the report to sort from your code. One solution is to build many report, one for each column which the user can choose.
Work hard, Work effectively.
Thanks for replying. There should be a way. I got a sample code, Its in VB, I tried it in C# but for some reason.. it doesn't work for me. Here's the code : Dim crSortDirection As SortDirection Dim crDatabaseFieldDefinition As DatabaseFieldDefinition Dim crSortField As SortField Dim iSortItem As Integer = 0 crDatabaseFieldDefinition = crReportDocument.Database.Tables(0).Fields(6) crSortField = crReportDocument.DataDefinition.SortFields(6) crSortField.Field = crDatabaseFieldDefinition 'crSortField.SortDirection = SortDirection.AscendingOrder crSortField.SortDirection = SortDirection.DescendingOrder There is no explanation available for the code. No matter what SortField I pass, it keeps throughing CrystalDecisions.CrystalReports.Engine.InvalidArgumentException -> Invalid SortNumber. Can you explain now? Zishan
-
Thanks for replying. There should be a way. I got a sample code, Its in VB, I tried it in C# but for some reason.. it doesn't work for me. Here's the code : Dim crSortDirection As SortDirection Dim crDatabaseFieldDefinition As DatabaseFieldDefinition Dim crSortField As SortField Dim iSortItem As Integer = 0 crDatabaseFieldDefinition = crReportDocument.Database.Tables(0).Fields(6) crSortField = crReportDocument.DataDefinition.SortFields(6) crSortField.Field = crDatabaseFieldDefinition 'crSortField.SortDirection = SortDirection.AscendingOrder crSortField.SortDirection = SortDirection.DescendingOrder There is no explanation available for the code. No matter what SortField I pass, it keeps throughing CrystalDecisions.CrystalReports.Engine.InvalidArgumentException -> Invalid SortNumber. Can you explain now? Zishan
Ar you sure your C# syntax is correct? In case you are passing a groupfield instead of a databaseField, use the base class: FieldDef = new FieldDefinition (); FieldDef = Report.Database.Tables [0].Fields [6]; Report.DataDefinition.SortFields [0].Field = FieldDef; Absolute faith corrupts as absolutely as absolute power Eric Hoffer All that is necessary for the triumph of evil is that good men do nothing. Edmund Burke
-
Ar you sure your C# syntax is correct? In case you are passing a groupfield instead of a databaseField, use the base class: FieldDef = new FieldDefinition (); FieldDef = Report.Database.Tables [0].Fields [6]; Report.DataDefinition.SortFields [0].Field = FieldDef; Absolute faith corrupts as absolutely as absolute power Eric Hoffer All that is necessary for the triumph of evil is that good men do nothing. Edmund Burke
Same problem :( Can I make a stored procedure and pass the "order by" parameter? I think that's going to solve the problem. I am using Crystal Reports that comes with the VS.net 2003. How can I call a stored procedure and pass the parameter? Many thanks. Zishan
-
Hello, I am a newbie in Crystal Reports. I need to sort the report based on the column that the user sets in the windows form. How do I do it? I've been googling with virtually no help :( Thanks in advance. Regards, Zishan
I have used crystal in a few of my apps and the way I handle sorting is by sorting the datasource ( i use a dataset as the source ). So based on a selected column by the user, sort the dataset into the desired order or load the data into the dataset by specifying the SORT keyword in the sql statement when retrieving the data. Hope this helps. Craigo
-
I have used crystal in a few of my apps and the way I handle sorting is by sorting the datasource ( i use a dataset as the source ). So based on a selected column by the user, sort the dataset into the desired order or load the data into the dataset by specifying the SORT keyword in the sql statement when retrieving the data. Hope this helps. Craigo
Craigo, I tried what you told me.. it is picking up all the records in the table without any order. I commented the t.SetDataSource line.. still the same result. I am not sure if this is the right way to define Data Source. Here is my code : Report2 t = new Report2(); string Query = "Select * from Orders order by ordertype asc"; SqlComm.CommandText = Query; SqlDataAdapter da = new SqlDataAdapter(SqlComm); DataSet data = new DataSet(); da.Fill(data); t.SetDataSource(data); this.Viewer.ReportSource = t; Zishan
-
Craigo, I tried what you told me.. it is picking up all the records in the table without any order. I commented the t.SetDataSource line.. still the same result. I am not sure if this is the right way to define Data Source. Here is my code : Report2 t = new Report2(); string Query = "Select * from Orders order by ordertype asc"; SqlComm.CommandText = Query; SqlDataAdapter da = new SqlDataAdapter(SqlComm); DataSet data = new DataSet(); da.Fill(data); t.SetDataSource(data); this.Viewer.ReportSource = t; Zishan
2 Things you can try. 1) change the code where you set the datasource to : t.SetDataSource(data.Tables[0]) 2) Add the line: t.EnableSaveDataWithReport=false; after you have set the datasource Let me know how you get on Craigo
-
2 Things you can try. 1) change the code where you set the datasource to : t.SetDataSource(data.Tables[0]) 2) Add the line: t.EnableSaveDataWithReport=false; after you have set the datasource Let me know how you get on Craigo
Hey Craig, thanks a lot man.. you saved my life.. although I don't have t.EnableSaveDataWithReport property but the problem is now solved.. Thanks for your help! :) Zishan