private void btnSubmit_Click(object sender, EventArgs e) { Button oBtn = sender as Button; if (oBtn != null && FormLoaded) { dataGridView1.Rows.Clear(); DyeParameters.FromDate = Convert.ToDateTime(dtpFromDate.Value.ToShortDateString()); DyeParameters.ToDate = Convert.ToDateTime(dtpToDate.Value.ToShortDateString()); DyeParameters.ToDate = DyeParameters.ToDate.AddHours(23); var CommTransGrps = repo.CommissionTransactions(DyeParameters).GroupBy(x => x.GreigeCom_GrnNo); using (var context = new TTI2Entities()) { foreach (var Grp in CommTransGrps) { var index = dataGridView1.Rows.Add(); dataGridView1.Rows[index].Cells[0].Value = Grp.FirstOrDefault().GreigeCom_GrnNo.ToString(); dataGridView1.Rows[index].Cells[1].Value = Grp.FirstOrDefault().GreigeCom_Transdate; dataGridView1.Rows[index].Cells[2].Value = Grp.FirstOrDefault().GreigeCom_Custdoc; var Pk = Grp.FirstOrDefault().GreigeCom_ProductType_FK; dataGridView1.Rows[index].Cells[3].Value = context.TLADM_Griege.Find(Pk).TLGreige_Description; dataGridView1.Rows[index].Cells[4].Value = Grp.FirstOrDefault().GreigeCom_Custdoc; dataGridView1.Rows[index].Cells[5].Value = Grp.Count(); dataGridView1.Rows[index].Cells[6].Value = Grp.Sum(x => x.GreigeCom_NettWeight); } } comboCustomers.Items.Clear(); comboQuality.Items.Clear(); frmViewCommissionReceipts_Load(this, null); } }