private void btnGenerateReport_Click(object sender, EventArgs e) { try { List <string> selectedMonth = (List <string>)lstMonth.SelectedItems.Cast <String>().ToList(); int selectedYear = Convert.ToInt32(cmbYear.SelectedItem.ToString()); int? BU = null; var AccountList = new List <Account>(); foreach (Account item in lstBUAcc.SelectedItems) { Account a = new Account(); a.AccountID = Convert.ToInt32(item.AccountID); AccountList.Add(a); } AccountMonthRevenue accMonthRevenue = new AccountMonthRevenue(); DataSet ds; if (cmbReportType.SelectedItem.ToString() == "Revenue Report") { ds = accMonthRevenue.GroupWiseRevenueReport(BU, selectedMonth, AccountList, selectedYear); } else { ds = accMonthRevenue.GroupWiseMarginReport(BU, selectedMonth, AccountList, selectedYear); } dgvReportView.AutoGenerateColumns = true; dgvReportView.DataSource = ds.Tables[0]; dgvReportView.AutoResizeColumns(); dgvReportView.Show(); } catch (Exception ex) { MessageBox.Show("An error occured while generating the report.\nPlease try again in sometime."); } }