cancel
Showing results for 
Search instead for 
Did you mean: 

I need help to Access Crystal Reports field values programmatically

Former Member
0 Kudos

I have tried a few different way but can't seem to find what I am looking for...

I am running a Crystal Report programmatically using c# WinForms, I need to be able to access the values of the fields in the group header 1 much like the way Visual CUT does when it runs the reports in its scheduler.

I have managed to get a hold of the GroupHeader1 Value by doing:

crystalReport.Rows[i].Rows.ToString();

and thought something like

crystalReport.Rows[i].Rows.Columns[0].Value 

would be available, but can't seem to find where I would be able to access the fields and their values at runtime.

I can see the formula I need by going through:

crystalReport.DataDefinition.FormulaFields["ToEmail"].Text 

But that just gives me the original value in the formula rather than what the report displays and sees.

I don't load the datasource of the report programmatically either, that is handled by the report itself, so can't even use that info.

Any pointers in the right direction would be greatly appreciated as it is frustrating the life out of me.

Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Moved to CR for .NET sdk forum.

Need to know what version of the SDK you are using and what verision of VS?

Don

Former Member
0 Kudos

Hi Don,

Thanks for the reply.

I am using Visual Studio 2012 on c# .NET Framework 4.5 with the the DLL version being 13.0.2000.0 (from the CrystalDecisions.Windows.Forms DLL).

Thanks,

Ian.

0 Kudos

Look in Programs and Feature for the specific version also, 13.0.2000.0 never changes, its the framework.

Also read the download page warnings and notes, may be you are using an Express version...

If not on SP 16 then download and use it.

Don

Former Member
0 Kudos

Ah, ok sorry. I was on version 15 (13.0.15.1840). I am also running the full version of Visual Studio Professional 2012. I have now updated to version 16 but still cannot see an obvious way to get the values of the group header 1 at runtime.

Thanks for your help.

0 Kudos

Ah, you did not have to go to SP 16 but no problem...

I'm curious, why do you need the data values?

If you add a doubleClick Event you can get the Data this way:

private void crystalReportViewer1_DoubleClickPage(object sender, PageMouseEventArgs e)

{

    //// do not edit this works

    //CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;

    //rptClientDoc = rpt.ReportClientDocument;

    //crystalReportViewer1.SetFocusOn(UIComponent.Page);

    //if (e.ObjectInfos != null)

    //{

    //    btnReportObjects.Text = "";

    //    btnReportObjects.Text += "Number of items in selected Row: " + e.ObjectInfos.Length.ToString() + "\n\n";

    //    foreach (ObjectInfo oi in e.ObjectInfos)

    //    {

    //        //btnReportObjects.Text += ">>>OBJECT : " + t + " <<<" + "\n";

    //        btnReportObjects.Text += "Fld Text: " + oi.Text.ToString() + "\n";

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

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

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

    //        try

    //        {

    //            foreach (FormulaField resultField in rptClientDoc.DataDefController.DataDefinition.FormulaFields)

    //            {

    //                if ((resultField.UseCount > 0) && (resultField.Text == oi.Text))

    //                {

    //                    CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject objField;

    //                    objField = (CrystalDecisions.ReportAppServer.ReportDefModel.FieldObject)rptClientDoc.ReportDefController.ReportDefinition.FindObjectByName(resultField.Text.ToString());

    //                    richTextBox1.Text += "Formula field object: " + objField.Name.ToString() + "\n"; // oi.DataContext.ToString() ;

    //                }

    //            }

    //        }

    //        catch (Exception ex)

    //        {

    //            MessageBox.Show("ERROR: " + ex.Message);

    //            return;

    //        }

    //        btnReportObjects.Text += "ObjectType: " + oi.ObjectType.ToString() + "\n";

    //        btnReportObjects.Text += "Tooltip: " + oi.ToolTip.ToString() + "\n";

    //        btnReportObjects.Text += "========================\n";

    //    }

    //    btnReportObjects.AppendText(" 'End' \n");

    //}

    ////do not edit - this works

    // Gary Chang sent me this not sure how it's diff than above but it's better

    CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;

    rptClientDoc = rpt.ReportClientDocument;

    //DateTime dtStart;

    //dtStart = DateTime.Now;

    //btnSQLStatement.Text += "\nReport End time: \n" + dtStart.ToString();

    rptClientDoc.ReportOptions.ConvertNullFieldToDefault = true;

    rptClientDoc.ReportOptions.ConvertOtherNullsToDefault = true;

    btnReportObjects.Text = "";

    int t = 0;

    if (e.ObjectInfos != null)

    {

        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";

                            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 += "Value: " + 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("\n\n");

                        }

                    }

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show("ERROR: " + ex.Message);

            }

        }

    }

Don

Answers (0)