我有一个GridView
,其中包含许多列,其中包含有关付款的详细信息。我想使用Crystal Reports创建一个报表,以便我选择一个特定的行,当我单击打印按钮时,我想获得相应行的报告。
答案 0 :(得分: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();
}
}
}