private void risLo_Click_1(object sender, EventArgs e) { try { var db = new MyDBContextDataContext(); var mahang = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, colMaHang).ToString(); //var lo = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, colLo).ToString(); //var tong = 0; //for (var i = 0; i < gridView1.RowCount - 1; i++) //{ // var dr = gridView1.GetDataRow(i); // if (dr["MaHang"].ToString() != mahang || string.IsNullOrEmpty(dr["lo"].ToString())) continue; // tong = tong + Convert.ToInt32(dr["SoLuongXuat"]); //} //MessageBox.Show(tong.ToString()); var khonvl = (from s in db.LoadData_TonKhoNVL_PhieuXuatKho(tungay, denngay) where s.mahang == mahang select s).ToList(); foreach (var item in khonvl) { for (var i = 0; i < gridView1.RowCount - 1; i++) { var dr = gridView1.GetDataRow(i); if (dr["lo"].ToString() != item.Lo || dr["Mahang"].ToString() != mahang) { continue; } item.toncuoiky = item.toncuoiky - Convert.ToInt32(dr["SoLuongXuat"]); } } risLo.DataSource = khonvl; risLo.DisplayMember = "Lo"; risLo.ValueMember = "Lo"; } catch (Exception) { // ignored //Console.WriteLine(ex); //throw; } }