cancel
Showing results for 
Search instead for 
Did you mean: 

Keep Group together in code

Former Member
0 Kudos

Hi,

We're using Crystal Reports 10 and there's an option in the Group expert to keep the group together.

Is there any way to access this option in code (C#)?

This is not working:

report.GroupHeaderSection1.SectionFormat.EnableKeepTogether = true;

Accepted Solutions (1)

Accepted Solutions (1)

tobias_weller
Participant
0 Kudos

Hi,

try the following code (groupNo is the number of your GroupHeaderSection1).


ISCRArea area  = reportClientDocument.ReportDefController
        .ReportDefinition.get_GroupHeaderArea(groupNo);
GroupAreaFormat groupAreaFormat = (GroupAreaFormat)area.Format.Clone(true);
groupAreaFormat.EnableKeepTogether = true;
            
 reportClientDocument.ReportDefController.ReportAreaController.SetProperty(
area,CrReportAreaPropertyEnum.crReportAreaPropertyFormat,groupAreaFormat);

Former Member
0 Kudos

I don't seem to have an ISCRArea class. I've searched using the object browser in Visual Studio, but no results.

What is 'reportClientDocument'? What type is it?

Could you explain the code a bit more, please?

tobias_weller
Participant
0 Kudos

The code is for using the RAS SDK.

I think you need the following dlls:

CrystalDecisions.ReportAppServer.ReportDefModel.dll

CrystalDecisions.ReportAppServer.ClientDoc.dll

reportClientDocument is of type ISCDReportClientDocument, which represents the report you are editing or creating with your code.

In the code I copy the group format and make my changes to this copy. After that I apply this changes to the group by calling the SetProperty method.

Hope this helps!

Former Member
0 Kudos

I think I'm missing something. I don't believe we're using RAS.

All reports are created in Visual Studio, so there locally stored in the project.

Can I still use the RAS SDK then?

There seems to be a workaround for it [here|http://msdn.microsoft.com/en-us/library/ms227402(VS.80).aspx], but I haven't read it completely yet.

tobias_weller
Participant
0 Kudos

There seems to be a workaround for it here, but I haven't read it completely yet.

Exactly that's the way I use it:


        private CrystalDecisions.CrystalReports.Engine.ReportDocument rdoc;
        private ISCDReportClientDocument rcd;

        rdoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
        rcd = rdoc.ReportClientDocument;
        rdoc.Load(reportFileName);

Former Member
0 Kudos

Ok, I tried it but I'm still missing something. I get an error

I'm guessing I have to implement the ISCDReportClientDocument interface in a class and use this class for my code.

Can you point me in the right direction please?

Error 1 The type 'CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument' 
is defined in an assembly that is not referenced. You must add a reference to
assembly 'CrystalDecisions.ReportAppServer.ClientDoc, Version=10.5.3700.0, 
Culture=neutral, PublicKeyToken=692fbea5521e1304'.  Form2.cs 93 13 TestCrystalReports

the code I use

testReport report = new testReport();
report.SetDataSource(ds);
ISCDReportClientDocument rcd1 = report.ReportClientDocument;
ISCRArea area = rcd1.ReportDefController.ReportDefinition.get_GroupHeaderArea(0);
GroupAreaFormat group = (GroupAreaFormat)area.Format.Clone(true);
group.EnableKeepGroupTogether = true;

Edited by: Bruno Latte on Mar 24, 2009 8:23 PM

Answers (2)

Answers (2)

0 Kudos

Install the latest Service Packs should fix the issue

former_member183750
Active Contributor
0 Kudos

What is the exact version of CR you are using?

What is the version of .NET you are using?

What is the version of the CR assembly crystaldecicions.crystalreports.engine.dll referenced in your project?

If you use the option in the Group expert of the CR designer, on the same data, do you see the expected result?

Ludek

Former Member
0 Kudos

If I'm not mistaken we're using CR 10.0.0.533, well, it's what's installed on my pc anyway.

The target framework is .NET 2.0.

crystaldecicions.crystalreports.engine.dll version 10.5.3700.0

If I go to 'Group Expert' > 'Options' > tab 'Options' and enable 'Keep Group together' , it does what I expect it to do.