0

我有一个GridView包含许多列的列,其中包含有关付款的详细信息。我想使用 Crystal Reports 创建一个报表,这样我想选择一个特定的行,当我单击打印按钮时,我想获取该相应行的报表。

4

1 回答 1

0

不太难。我经常提到人们http://csharp.net-informations.com/crystal-reports/csharp-crystal-reports-string-parameter.htm

基本上使用参数创建您的 Crystal Report 以获取 payment_id(或某种形式的“主键”),然后将打印按钮设置为执行以下操作:

using System;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ReportDocument cryRpt = new ReportDocument();
            cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt");

            ParameterFieldDefinitions crParameterFieldDefinitions ;
            ParameterFieldDefinition crParameterFieldDefinition ;
            ParameterValues crParameterValues = new ParameterValues();
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();

            crParameterDiscreteValue.Value = dataGridView1.SelectedRows[0].Cells["payment_id"].Value.ToString();;
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields;
            crParameterFieldDefinition = crParameterFieldDefinitions["payment_id"];
            crParameterValues = crParameterFieldDefinition.CurrentValues;

            crParameterValues.Clear();
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);

            crystalReportViewer1.ReportSource = cryRpt;
            crystalReportViewer1.Refresh(); 

        }
    }
}
于 2012-11-17T09:29:06.020 回答