0

我正在创建一个计算净重的应用程序,我必须在其中一个表单上为用户提供从下拉组合框中选择项目的选项,并为用户提供从日期时间选择器,我必须将其作为参数放在报告的文本框中,填充组合框以选择项目没有任何问题,因为这些项目在数据库表中,我使用 sql 命令得到了列然后将其作为参数传递以填充下拉列表,然后设置相同但日期时间选择器用户可以选择他们希望的任何日期如何将该值传递给报告以直观地了解我正在谈论的内容单击我使用 GUI 创建了报告,并且 gui 生成了这段代码,该代码使用我设置的一个参数加载报告。

private void PieceCodepc_Load(object sender, EventArgs e)
{

    reportViewer1.Visible = false;
    // TODO: This line of code loads data into the 'dataSet1.DataTable1' table. You can move, or remove it, as needed.
    this.dataTable1TableAdapter.Fill(this.dataSet1.DataTable1);

}

private void button1_Click(object sender, EventArgs e)
{
    // TODO: This line of code loads data into the 'tableforReport.CandyPieceSize' table. You can move, or remove it, as needed.
    this.CandyPieceSizeTableAdapter.Fill(this.tableforReport.CandyPieceSize);
    // TODO: This line of code loads data into the 'empty.Piece_Dimension_Master_Data' table. You can move, or remove it, as needed.
    this.Piece_Dimension_Master_DataTableAdapter.Fill(this.empty.Piece_Dimension_Master_Data, comboBox1.SelectedValue.ToString());

    this.reportViewer1.RefreshReport();    
}
4

1 回答 1

0

I got it working wanted to post it as an answer so others can benefit from similar situations.

 private void setFiltersParameters()
        {
            this.Piece_Dimension_Master_DataTableAdapter.Fill(this.empty.Piece_Dimension_Master_Data, comboBox1.SelectedValue.ToString());
            ReportParameter date = new ReportParameter("date", dateTimePicker1.Text.ToString());
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { date });
            this.reportViewer1.RefreshReport();
        }

When the button is clicked i call the above method as such

  private void button2_Click(object sender, EventArgs e)
        {
            setFiltersParameters();
            reportViewer1.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
            button1.PerformClick();
            reportViewer1.Visible = true;
        }
于 2015-01-19T21:07:05.187 回答