Question

I'm trying to loop through crystal sub-reports using CRAXDDRT in C#2010 and I'm hitting an issue. I've found a lot of VB6 code that looks like this...

Dim crxDatabaseTables As CRAXDRT.DatabaseTables
Dim crxDatabaseTable As CRAXDRT.DatabaseTable
Dim crxSections As CRAXDRT.Sections
Dim crxSection As CRAXDRT.Section
Dim CRXReportObject As Object

For Each crxSection In crxSections
    For Each CRXReportObject In crxSection.ReportObjects
       If CRXReportObject.Kind = crSubreportObject Then
           ' loop code here
       End If
    Next
Next

While this looks & works great in VB6 this won't work in c# because CRXReportObject is an object, so this line...

 If CRXReportObject.Kind = crSubreportObject Then

...wouldn't work as 'Kind' is not a method on object. Does anyone have any suggestions to get around this? Before anyone suggests not using Crystal Report ActiveX objects, we can't. We're stuck with it... This is the code so far...

foreach (CRAXDDRT.Section section in crystalReport.Sections)
{
    foreach (object item in section.ReportObjects)
    {
        //If item.Kind = crSubreportObject Then
            //loop code here
        //}
    }
}
Was it helpful?

Solution

May I just say that this solution is not ideal, but if I can't find a better solution this is what I'm gonna go with...

CRAXDDRT.SubreportObject subReport = null;

foreach (CRAXDDRT.Section section in crystalReport.Sections)
{
    foreach (object item in section.ReportObjects)
    {
        subReport = item as CRAXDDRT.SubreportObject;
        if (subReport != null)
        {
            //loop code here
        }
    }
}

While this works I would welcome a better solution...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top