I have an application that is doing all of our reporting with locally stored RDLs. I have two forms, one is a simple viewer that contains a TabPageControl, and the other is an FLP of controls that the user can use to select report parameters. We are planning on having over 30+ options, but at the moment we only have around 5 (certain ones display for certain reports, the rest are hidden).
The issue I'm running into is that I need to have some way to get the options they chose out of a List or Collection. The method I'm using right now is
public void AddReportToViewer(string reportName, List<ReportParameter> parameterList = null)
{
TabPage newPage = new TabPage();
ReportViewer reportViewer = new ReportViewer();
newPage.Text = reportName;
newPage.Controls.Add(reportViewer);
tbcReports.TabPages.Add(newPage); //adding the report viewer to page, should do this at the end of the method
reportViewer.Reset();
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.LocalReport.ReportPath = "MyPath/reportName";
ReportDataSource rds = new ReportDataSource();
//parse parameters to individual objects to use with method calls
int parameterEmployeeID = 0;
int parameterStoreID = 0;
List<int> parameterStoreIDs = null;
DateTime parameterFromDate = DateTime.Now;
DateTime parameterToDate = DateTime.Now;
//Use parameters to get objects, just one here, but we have multiple
List<EmployeeTimeclockReportObjects> timeclock = reportBL.getEmployeeTimeclock(parameterEmployeeID, parameterStoreID, parameterFromDate, parameterToDate);
reportBindingSource.DataSource = timeclock;
rds = new ReportDataSource("TimeclockEntries", reportBindingSource);
reportViewer.LocalReport.DataSources.Add(rds);
reportViewer.RefreshReport();
reportViewer.Dock = DockStyle.Fill;
}
This all works, but here's where I need help
int parameterEmployeeID = 0;
int parameterStoreID = 0;
List<int> parameterStoreIDs = null;
DateTime parameterFromDate = DateTime.Now;
DateTime parameterToDate = DateTime.Now;
I need to strip the values from the list of report parameters so I can use them in the data population methods. For example, I'm doing something like...
int parameterEmployeeID = Convert.ToInt32(parameterList[parameterList.FindIndex(x => x.Name == "employeeID")].Values[0]);
But then I run into issues on the List<int> parameterStoreIDs
, because I can't convert a StringCollection to a List of ints.
Does anyone have any recommendations on either a) converting the StringCollection to a list of ints, or b) anything else I could try doing to get the information back from the second form besides a List<ReportParameters>
???
For question (a), consider something like this:
I am not clear on what variable in the code would be the StringCollection
, so for the sake of the example I'm just calling it strings
.
List<int> ints = strings.Cast<string>(s => Convert.ToInt32(s)).ToList();