我是完全新的報告Visual Studio C#..我嘗試尋找初學者的一些教程,但我不成功..我只是發現代碼示例,沒有真正解釋的基礎知識...我寫了要求,並且運行良好,但如下它不會顯示在Visual Studio 2013..My代碼報表查看器控制任何事情都是一些代碼:RDLC報告使用C#
// This method is in a class named Customers.
// When the user clicks the first column of the datagrid view(I have placed a button
// in the first column of the datagrid) a new form opens (ReportForm) and i pass
// the DataSet called dsReport to its constructor.
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 0)
{
DataSet dsReport = new DataSet();
DataTable tbl = dsReport.Tables.Add();
tbl.Columns.Add("CustomerName", typeof(string));
tbl.Columns.Add("CustomerAddress", typeof(string));
tbl.Columns.Add("MaritalStatus", typeof(string));
tbl.Columns.Add("CustomerType", typeof(string));
tbl.Columns.Add("ImagePath", typeof(string));
foreach (Customer cust in customerList)
{
DataRow dr = dsReport.Tables[0].NewRow();
dr["CustomerName"] = cust.Name;
dr["CustomerAddress"] = cust.Address;
dr["MaritalStatus"] = cust.MaritalStatus;
dr["CustomerType"] = cust.CustomerType;
dr["ImagePath"] = cust.ImagePath;
dsReport.Tables[0].Rows.Add(dr);
}
ReportForm report = new ReportForm(dsReport);
report.Show();
}
}
//Following is the code for the ReportForm Class
//I do not get any results in the report viewer
//I just see the message "The source of the report definition has not been specified"
public ReportForm(DataSet dsReport)
{
InitializeComponent();
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(myReportSource);
this.reportViewer1.ProcessingMode = ProcessingMode.Local;
this.reportViewer1.LocalReport.Refresh();
this.reportViewer1.RefreshReport();
}
private void ReportForm_Load(object sender, EventArgs e)
{
this.reportViewer1.RefreshReport();
}
/*請注意,我在運行代碼調試器和數據集被正確填充 ,所以reportViewer1.LocalReport..Also我沒有 添加任何數據源到項目,我沒有添加任何報告文件(.rdl)文件 到項目*/
最後誰能請回答下列問題:
Q1。我是否必須包含一個數據源才能使用報告 查看器工具? Q2302。我是否必須在項目中包含.rdl文件才能顯示報告?
Q3。報告查看器工具和.rdl文件是否相同或是否與 不同?
謝謝布拉德利Uffner的簡短,清晰和簡潔的答案...請考慮以下情況......我已經將數據源和.rdl文件添加到項目並已成功綁定到該報告查看器...報告查看器現在正常工作並顯示所有記錄...假設我有一個名爲Form1的窗體,其中包含一個帶有5列的DatagridView ..現在,當單擊任何一行的第一列時出現一個新窗體使用報告查看器並僅在報告查看器中顯示該行...我該如何解決此問題? – user2423083
在按鈕上單擊將數據行復制到新的DataTable,然後使用該DataTable作爲報告的數據源。報告只能處理您傳遞的數據。 –
布拉德利烏弗納我添加了一個數據集的項目和一個.rldc文件。然後,我將一個reportviewer添加到表單中,然後用報告AND IT WORKED綁定數據集和.rldc文件。我使用參數來獲取單行數據...現在這種方法的問題是數據集和.rldc被綁定到報表查看器。由於自動應用的綁定,我無法在運行時通過代碼更改數據集...你能告訴我如何通過代碼手動完成所有這些工作......如果可能的話,請顯示工作代碼..也請在開始時看到我的代碼。 – user2423083