cancel
Showing results for 
Search instead for 
Did you mean: 

How to embed Crystal Reports viewer in a B1 Form.

paolo_fornari3
Participant
0 Kudos

Hi,

i'm trying to embed Crystal Reports viewer in a B1 Form, but i'm having troubles.

I'm using:

- Visual Studio 2008

- SAP Business One 8.8 SP: 00 PL: 09

I've already took a look at other threads but haven't found a solution.

I'm using ActiveX feature like this:


        Dim Actx As SAPbouiCOM.ActiveX
        Dim oItem As SAPbouiCOM.Item

        oItem = Form.Items.Add("CrViewer", SAPbouiCOM.BoFormItemTypes.it_ACTIVE_X)
        oItem.Left = 5
        oItem.Top = 5
        oItem.Width = 250
        oItem.Height = 200

        ' Create the new ActiveX control
        Actx = DirectCast(oItem.Specific, SAPbouiCOM.ActiveX)
        Actx.ClassID = "{548C6316-751F-4B34-B8D9-A56FCEE53BC8}" 'Corresponds to Crystal ActiveX Report Viewer Control 10.5
        Actx.Object.ReportSource = r 'r is my CrystalDecisions.CrystalReports.Engine.ReportDocument already prepared

When i set the ReportSource property i got this exception:

System.Runtime.InteropServices.COMException (0x80020003): Impossibile trovare membro. (Eccezione da HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))

in Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateSet(Object o, Type& objType, String name, Object[] args, String[] paramnames, Boolean OptimisticSet, CallType UseCallType)

in Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean RValueBase, CallType CallType)

in Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateSetComplex(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean OptimisticSet, Boolean RValueBase)

Seems that ReportSourceProperty does not exists, but im' sure that it exists!!

In fact, if in the immediate windows i type:

 ? Actx.Object.ReportSource

I receive Nothing! so the property is accessible.

I really cannot make it work, can anyone help please?

Thanks

Paolo

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello

You should create an CR object, and assign it to Actx.Object

' Create the new ActiveX control
        Actx = DirectCast(oItem.Specific, SAPbouiCOM.ActiveX)
        Actx.ClassID = "{548C6316-751F-4B34-B8D9-A56FCEE53BC8}"
' now connect ActiveX into CR object
       Dim CRV As CrystalDecisions.Windows.Forms.CrystalReportViewer = Actx.Object
' Use the CRV to set the properties
       CRV.ReportSource = r 'r is my CrystalDecisions.CrystalReports.Engine.ReportDocument already prepared


If it is now working, go ahead with the classical way Windows form with CR Viewer, and you can display it.

Regards,

J

paolo_fornari3
Participant
0 Kudos

Hi, János,

thank you for the answer.

I tryed, but the istruction:

Dim CRV As CrystalDecisions.Windows.Forms.CrystalReportViewer = Actx.Object

throws an InvalidCastException:

Unable to cast COM object of type 'System.__ComObject' to class type 'CrystalDecisions.Windows.Forms.CrystalReportViewer'. Instances of types that represent COM components cannot be cast to types that do not represent COM components; however they can be cast to interfaces as long as the underlying COM component supports QueryInterface calls for the IID of the interface.

Former Member
0 Kudos

{548C6316-751F-4B34-B8D9-A56FCEE53BC8} is a GUID for COM Object CrystalActiveXReportViewerLib105.CrystalActiveXReportViewer. It cannot be converted to .NET object CrystalDecisions.Windows.Forms.CrystalReportViewer. Add COM-reference CrystalActiveXReportViewerLib105 to your project and try to use this code:

SAPbouiCOM.ActiveX activeX = oItem.Specific as SAPbouiCOM.ActiveX;
activeX.ClassID = "{548C6316-751F-4B34-B8D9-A56FCEE53BC8}";

CrystalActiveXReportViewerLib105.CrystalActiveXReportViewer viewer = (CrystalActiveXReportViewerLib105.CrystalActiveXReportViewer)activeX.Object;