SAP Knowledge Base Article - Public

1704452 - ER: How To: Get the values from a report object in .NET Windows Application

Symptom

  • Legacy RDC had a CRViewer Event that when double clicking on a row or object would return a collection and the values.
  • CrystalDecisions.Windows.Forms viewer did not have the same ability.

Environment

Crystal Reports for Visual Studio 2010 Service Pack 2 or earlier

Cause

Enhancement has been added to allow this functionality - ADAPT01607928

Resolution

Crystal Reports for Visual Studio 2010 Service Pack 3.

  1. Add a Double Click Event to the Viewer form.
  2. Then use the event to trigger the collection info to be populated.
  3. Create a Rich TextBox to display the info collected.

Use the following Code to get the info and display it:

using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Windows.Forms;
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.DataDefModel;
using CrystalDecisions.ReportAppServer.ReportDefModel ;
using CrystalDecisions.ReportAppServer.CommLayer;
using CrystalDecisions.ReportAppServer.CommonControls;

private void crystalReportViewer1_DoubleClickPage(object sender, PageMouseEventArgs e)
{
    CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;
    rptClientDoc = rpt.ReportClientDocument;

    rptClientDoc.ReportOptions.ConvertNullFieldToDefault = true;
    rptClientDoc.ReportOptions.ConvertOtherNullsToDefault = true;

    btnReportObjects.Text = "";
    int t = 0;
    foreach (ObjectInfo oi in e.ObjectInfos)
    {
        try
        {
            if (oi.ObjectType.ToString() != "GroupChart")
            {
                if (oi.ObjectType.ToString() != "OleObject")
                {
                    if (oi.ObjectType.ToString() != "CrossTab")
                    {
                        // This is the field you double clicked on, in the viewer
                        if (oi.Name == e.ObjectInfo.Name)
                            btnReportObjects.Text += ">>> SELECTED OBJECT - you clicked on<<<" + "\n";

                        // Note: btnReportObjects is a simple text box to display the output

                        btnReportObjects.Text += "DataContext: " + oi.DataContext.ToString() + "\n";
                        btnReportObjects.Text += "GroupNamePath: " + oi.GroupNamePath.ToString() + "\n";
                        btnReportObjects.Text += "Hyperlink: " + oi.Hyperlink.ToString() + "\n";

                        string textBox1 = String.Empty;
                        foreach (FormulaField resultField in rptClientDoc.DataDefController.DataDefinition.FormulaFields)
                        {
                            CrystalDecisions.ReportAppServer.ReportDefModel.ReportObjects FormulaFldobjs;
                            FormulaFldobjs = rptClientDoc.ReportDefController.ReportObjectController.GetReportObjectsByKind(CrReportObjectKindEnum.crReportObjectKindField);
                            t = rptClientDoc.DataDefController.DataDefinition.FormulaFields.FindIndexOf(resultField);
                            CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject objField;
                            objField = (CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject)FormulaFldobjs[t];
                            CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject objField2 = (CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject)objField.Clone(true);

                            if (oi.Name.ToString() == objField2.Name.ToString())
                            {
                                btnReportObjects.Text += "Name: " + oi.Name.ToString() + " -> " + objField2.DataSourceName.ToString() + "\n";
                            }

                            t++;
                        }

                        //btnReportObjects.Text += "Name: " + oi.Name.ToString() + "\n";
                        btnReportObjects.Text += "Text: " + oi.Text.ToString() + "\n";
                        btnReportObjects.Text += "ObjectType: " + oi.ObjectType.ToString() + "\n";
                        btnReportObjects.Text += "Tooltip: " + oi.ToolTip.ToString() + "\n";
                        btnReportObjects.Text += "========================\n";
                        btnReportObjects.Text += richTextBox1;
                        btnReportObjects.AppendText(" 'End' \n");
                    }
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("ERROR: " + ex.Message);
        }
    }
}

 

Keywords

DoubleClick, Crystal Reports, Crystal reports for Visual Studio 2010, event, RDC Event , KBA , BI-DEV-NET-SDK , .NET SDK / COM SDK , Product Enhancement

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio