private void dtgvDsHangNhap_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if (dtgvDsHangNhap.Columns[e.ColumnIndex].Name == "DonGia" || dtgvDsHangNhap.Columns[e.ColumnIndex].Name == "SoLuongNhap") { if (dtgvDsHangNhap.Rows[e.RowIndex].Cells["SoLuongNhap"].Value != null && dtgvDsHangNhap.Rows[e.RowIndex].Cells["DonGia"].Value != null) { dtgvDsHangNhap.Rows[e.RowIndex].Cells["ThanhTien"].Value = (Convert.ToDecimal(dtgvDsHangNhap.Rows[e.RowIndex].Cells["SoLuongNhap"].Value.ToString()) * Convert.ToDecimal(dtgvDsHangNhap.Rows[e.RowIndex].Cells["DonGia"].Value.ToString())).ToString(); } } else if (dtgvDsHangNhap.Columns[e.ColumnIndex].Name == "MaHang") { if (!String.IsNullOrEmpty(dtgvDsHangNhap.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()) && !String.IsNullOrWhiteSpace(dtgvDsHangNhap.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString())) { HangHoaBLL bLL = new HangHoaBLL(); var data = bLL.GetInfoHangByID(dtgvDsHangNhap.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()); dtgvDsHangNhap.Rows[e.RowIndex].Cells["TenHang"].Value = data?.Rows[0][1].ToString(); } } }