我试图弄清楚如何在我的 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 我可以指定这个,但我不确定如何。任何建议表示赞赏!