2013-04-16 58 views
0

我想弄清楚如何在我的c#代碼後面提供數據源。我試圖將所有列出的報告和一個報告查看器作爲這些報告的主要容器使用一個組合框。這是我的代碼:尚未爲數據源dsMyData提供數據源實例。 Winforms

 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(); 

     } 

我想在代碼私人無效comboBox1塊,我可以指定這個,但我不知道如何。任何建議表示讚賞!

回答

0

以爲我會發布我的解決方案來解決這個問題。我爲數據庫添加了一個表格以用於報告配置。這樣我可以在將來添加或刪除報告。它包含諸如報告名稱,報告友好名稱,報告路徑和數據集等列,因此我可以簡單地使用字段中的值來避免此問題。

+0

感謝您回來發佈您的解決方案。 – elmart