cancel
Showing results for 
Search instead for 
Did you mean: 

Crystal Reports - programatically create a new group

Former Member
0 Kudos

Hi, I'm building a report on the fly and I need to create groups.  From googling, it seems that I need to clone from an existing group.  In order to that, I need a single group in my blank report.  I'm trying to create a dynamic group as in http://www.encodedna.com/2013/06/dynamically-change-groups-crystalreports.htm but my Insert Group menu option is greyed out.  Any ideas?

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

What SDK are you using and what version?

Former Member
0 Kudos

Good questions.  I have Crystal Reports 2008, CR Developer, Version 12.3.0.601.

0 Kudos

So you are not writing an application using our SDK and simply attempting to do this with CR Designer itself?

Former Member
0 Kudos

Oh, I AM doing this in the SDK, I'm sorry for the bad answers, I just took over this Crystal Reports project and am just getting up to speed.  I'm not sure where to get the SDK version.  If it helps, the CrystalDecisions.CrystalReports.Engine assembly has a Runtime Version of v2.0.50727 and a Version of 13.0.2000.0. 

0 Kudos

OK now we are getting somewhere. I moved your post to the .NET SDK forum.

You don't need to start with a group, code below using the -1 index is to add a new group.

Not clear when/why you said "but my Insert Group menu option is greyed out. "

Does not make sense, except you may be trying to view the report after adding the group... I don't know, not enough info on the workflow...

Try this sample,

        Dim boGroup As CrystalDecisions.ReportAppServer.DataDefModel.Group
        Dim boTableIndex As Integer
        Dim boTable As CrystalDecisions.ReportAppServer.DataDefModel.Table
        Dim boField As CrystalDecisions.ReportAppServer.DataDefModel.Field

        'get report object from session or create a new report object for unmanaged reports simply open the report here
        If Not (Session("boReportDocument") Is Nothing) Then
            boReportDocument = CType(Session("boReportDocument"), CrystalDecisions.CrystalReports.Engine.ReportDocument)
        Else
            boReportDocument = New CrystalDecisions.CrystalReports.Engine.ReportDocument()
            boReportDocument.Load(Server.MapPath("SimpleRCAPIReport.rpt"))
            Dim boReportClientDocument As CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument = boReportDocument.ReportClientDocument

            'Create a new Group Object
            boGroup = New CrystalDecisions.ReportAppServer.DataDefModel.Group

            'Now find the database field that will be used as the grouping condition - you can reference it directly, but this method
            'can be used if you only know the table name
            boTableIndex = boReportClientDocument.DatabaseController.Database.Tables.FindByAlias("Customer")
            boTable = boReportClientDocument.DatabaseController.Database.Tables(boTableIndex)

            'Now get the field in the Table
            boField = boTable.DataFields.FindField("{Customer.City}", CrystalDecisions.ReportAppServer.DataDefModel.CrFieldDisplayNameTypeEnum.crFieldDisplayNameFormula)

            'Set that field as the field to group on
            boGroup.ConditionField = boField

            'And finally Add it to the report
            boReportClientDocument.DataDefController.GroupController.Add(-1, boGroup)

        End If

For more samples click on the Overview tab and on the left you'll find a link to download sample applications.

Don

Former Member
0 Kudos

Great! This is just what I need.  Ignore the "Insert Group" is greyed-out issue then because that was in the designer and I much prefer creating a new group fully programmatically.  I'll try this out. Thanks!

Answers (0)