0
我試圖將DataGridView作爲數據源用於報表,我想在報表中顯示DataGridView中的表。我搜索,我發現這裏的代碼,以便告訴我做這樣的事情:在我的報表生成報告使用DataGridView作爲報表查看器的數據源
private void GenerateReport_Click(object sender, EventArgs e)
{
ReportForm reportForm = new ReportForm(DataGrid);
reportForm.ShowDialog();
}
按鈕:
private DataGridView grid;
private void ReportForm_Load(object sender, EventArgs e)
{
DataTable dt = (DataTable)grid.DataSource;
dt.TableName = "reportSource";
reportViewer1.ProcessingMode = ProcessingMode.Local;
ReportDataSource rds = new ReportDataSource("reportSource", dt);
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(rds);
this.reportViewer1.RefreshReport();
}
ReportForm的構造
public ReportForm(DataGridView grid)
{
InitializeComponent();
this.grid = grid;
}
但我有一個空的報告。
你收到一個異常或報表查看器顯示任何錯誤? –
您不應該向我們展示您的ReportForm的構造函數嗎?將您的構造函數的參數更改爲傳遞DataTable,而不是整個網格控件。 – LarsTech
不只是一個空的表單,我將使用ReportForm的構造函數更新問題,但我已經嘗試傳遞dataTable,並得到相同的結果。 – user3670112