Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Crystal Reports -> Sorting Data

Crystal Reports -> Sorting Data

Scheduled Pinned Locked Moved C#
questionalgorithmshelp
9 Posts 5 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    Zishan Haider
    wrote on last edited by
    #1

    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

    Y C 2 Replies Last reply
    0
    • Z Zishan Haider

      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

      Y Offline
      Y Offline
      Yulianto
      wrote on last edited by
      #2

      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.

      Z 1 Reply Last reply
      0
      • Y Yulianto

        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.

        Z Offline
        Z Offline
        Zishan Haider
        wrote on last edited by
        #3

        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

        R 1 Reply Last reply
        0
        • Z Zishan Haider

          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

          R Offline
          R Offline
          Rob Graham
          wrote on last edited by
          #4

          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

          A 1 Reply Last reply
          0
          • R Rob Graham

            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

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • Z Zishan Haider

              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

              C Offline
              C Offline
              Craig G Fraser
              wrote on last edited by
              #6

              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

              Z 1 Reply Last reply
              0
              • C Craig G Fraser

                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

                Z Offline
                Z Offline
                Zishan Haider
                wrote on last edited by
                #7

                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

                C 1 Reply Last reply
                0
                • Z Zishan Haider

                  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

                  C Offline
                  C Offline
                  Craig G Fraser
                  wrote on last edited by
                  #8

                  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

                  Z 1 Reply Last reply
                  0
                  • C Craig G Fraser

                    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

                    Z Offline
                    Z Offline
                    Zishan Haider
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups