我正在试图弄清楚如何在我的c#代码中提供数据源。我正在尝试使用一个组合框,列出我的所有报告,并使用一个报告查看器作为这些报告的主要容器。这是我的代码:
private void BaseForm_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'bgdataDataSet.FoodTable' table. You can move, or remove it, as needed.
this.FoodTableTableAdapter.Fill(this.bgdataDataSet.FoodTable);
BindingList<Data> _comboItems = new BindingList<Data>();
_comboItems.Add(new Data { Name = "Select", RptValue = "Select" });
_comboItems.Add(new Data { Name = "All Food Values", RptValue = "AllFoodValues.rdlc" });
_comboItems.Add(new Data { Name = "All Readings", RptValue = "AllReadings.rdlc" });
_comboItems.Add(new Data { Name = "Avg Food Values by Date", RptValue = "AvgFoodValuesByDate.rdlc" });
_comboItems.Add(new Data { Name = "Avg Food Values by Meal", RptValue = "AvgFoodValuesByMeal.rdlc" });
_comboItems.Add(new Data { Name = "Avg Readings by Date", RptValue = "AvgReadingsByDate.rdlc" });
_comboItems.Add(new Data { Name = "Avg Readings by Time", RptValue = "AvgReadingsByTime.rdlc" });
_comboItems.Add(new Data { Name = "Avg Readings by Event", RptValue = "AvgReadingsByEvent.rdlc" });
_comboItems.Add(new Data { Name = "Blood Pressure Chart", RptValue = "BPChart.rdlc" });
_comboItems.Add(new Data { Name = "Blood Pressure Report", RptValue = "BPReport.rdlc" });
_comboItems.Add(new Data { Name = "Detailed Food Values by Meal", RptValue = "DetailFoodValuesByMeal.rdlc" });
_comboItems.Add(new Data { Name = "Doctor Detailed Report", RptValue = "DoctorDetailedReport.rdlc" });
_comboItems.Add(new Data { Name = "Food Chart", RptValue = "FoodChart.rdlc" });
_comboItems.Add(new Data { Name = "Pumper Detail Report", RptValue = "PumperDetailReport.rdlc" });
_comboItems.Add(new Data { Name = "Reading Charts", RptValue = "ReadingCharts.rdlc" });
_comboItems.Add(new Data { Name = "Total Daily Food Intake", RptValue = "TotalIntakeDailyFood.rdlc" });
comboBox1.DataSource = _comboItems;
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "RptValue";
comboBox1.SelectedValue = "Select";
this.rvDoctorReportViewer.RefreshReport();
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex > 0)
{
string strReport;
strReport = "ReportViewer." + comboBox1.SelectedValue.ToString();
rvDoctorReportViewer.Reset();
rvDoctorReportViewer.LocalReport.ReportPath = "Reports/" + comboBox1.SelectedValue.ToString() + "";
rvDoctorReportViewer.LocalReport.ReportEmbeddedResource = strReport;
rvDoctorReportViewer.RefreshReport();
}
我正在考虑代码块private void comboBox1,我可以指定这个,但我不确定如何。任何建议表示赞赏!
答案 0 :(得分:0)
以为我会发布我的解决方案来解决这个问题。我在数据库中添加了一个表来进行报告配置。这样我将来可以添加或删除报告。它包含报告名称,报告友好名称,报告路径和数据集等列,因此我可以使用字段中的值来避免此问题。