SAP Knowledge Base Article - Public

1214063 - How do you access the click events of the Crystal Reports Viewer a Visual Basic or Visual C++ application?

Symptom

Accessing the click and double-click events in the Crystal Reports Viewer

Resolution

The following demonstrates how to generate a message box when clicking on the Crystal Reports Viewer.

Visual Basic

In Visual Basic, the Clicked and DblClicked events of the Crystal Reports viewer pass a CRVEventInfo object in as the third parameter. Note that the CRVEventInfo object contains a 'Text' property. Declare an EventInfo object of type CRVIEWERLibCtl.CRVEventInfo , then in the Clicked event, set the EventInfo parameter to be of that type (see code sample below):

Dim myEvent As CRVIEWERLibCtl.CRVEventInfo

Dim myFields As CRVIEWERLibCtl.CRFields

Dim myField As CRVIEWERLibCtl.CRField

Dim i As Integer

Private Sub CRViewer1_Clicked(ByVal x As Long, ByVal y As Long, EventInfo As Variant, UseDefault As Boolean)

Set myEvent = EventInfo

Set myFields = myEvent.GetFields

MsgBox myEvent.Text

End Sub

Visual C++

In Visual C++, type cast the EventInfo object to be of type CRVEventInfo in the OnClicked or OnDoubleClicked method. Note that you are not able to access the Text property in the CRVEventInfo object. You do have access to an IUnknown and IDispatch pointer in the CRVEventInfo object. Use a Smart pointer to access the 'Text' property (see code sample below):

void CEmbeddable_DesignerDlg::OnClickedCrviewer2(long x, long y, VARIANT

FAR* EventInfo, BOOL FAR* UseDefault)

{

if(EventInfo->vt != VT_DISPATCH)

{

ASSERT( FALSE );

return;

}

// Create a Smart Pointer to the EventInfo interface

CComPtr<ICRVEventInfo> pEvent((ICRVEventInfo*)EventInfo->pdispVal );

// Use the Smart Pointer to access the 'Text' property

_bstr_t string = pEvent->Text;

char* pTest1 = (char*) string;

CString sClickedText( pTest1 );

CString sMsg;

sMsg.Format( "Click Event Received:\nx = %ld\ny = %ld\n\n%s", x, y, sClickedText );

AfxMessageBox( sMsg );

}

Keywords

CLICK EVENT CRVIEWER SMART VIEWER EVENTS DOUBLE CLICK Report Designer Component Crystal Reports Viewer Click events C++ VB , KBA , BI-DEV , Business Intelligence Software Development Kits (SDKs) , How To

Product

SAP Crystal Reports 8.0