private void grdViewSTVDetails_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) { decimal invoicedQty; decimal receivedQty; decimal difference = 0; var row = grdViewSTVDetails.GetFocusedDataRow(); string guid = row["GUID"].ToString(); receiveDoc.FindByGUID(guid); if (!receiveDoc.IsColumnNull("InvoicedNoOfPack")) { invoicedQty = receiveDoc.InvoicedNoOfPack; receivedQty = receiveDoc.NoOfPack; difference = invoicedQty - receivedQty; } if (difference > 0) { lcDiscrepancy.Visibility = LayoutVisibility.Always; bool notEntered = true; bool isNewRow = true; if (receiveDocShortage.RowCount > 0) { var noOfDiscrepancyEntries = receiveDocShortage.CountByGUID(guid); if (receiveDocShortage.FindFirstByGUID(guid)) { notEntered = false; for (int i = 0; i < noOfDiscrepancyEntries; i++) { receiveDocShortage.SetColumn("ManufacturerName", Manufacturer.GetName(receiveDoc.ManufacturerId)); receiveDocShortage.SetColumn("UnitName", ItemUnit.GetUnitText(receiveDoc.UnitID)); receiveDocShortage.SetColumn("BatchNo", receiveDoc.GetColumn("BatchNo")); receiveDocShortage.SetColumn("ExpDate", receiveDoc.GetColumn("ExpDate")); receiveDocShortage.SetColumn("FullItemName", receiveDoc.GetColumn("FullItemName")); receiveDocShortage.SetColumn("StockCode", receiveDoc.GetColumn("StockCode")); receiveDocShortage.SetColumn("GUID", receiveDoc.GetColumn("GUID")); if (noOfDiscrepancyEntries > 1) { receiveDocShortage.SetColumnNull("NoOfPacks"); } else { receiveDocShortage.NoOfPacks = difference; } } } } if (receiveDocShortage.RowCount == 0 || notEntered) { //Prepare the columns used for display } if (notEntered) { receiveDocShortage.AddNew(); if (!receiveDocShortage.DefaultView.ToTable().Columns.Contains("FullItemName")) { receiveDocShortage.AddColumn("FullItemName", typeof(string)); receiveDocShortage.AddColumn("UnitName", typeof(string)); receiveDocShortage.AddColumn("ManufacturerName", typeof(string)); receiveDocShortage.AddColumn("StockCode", typeof(string)); receiveDocShortage.AddColumn("ExpDate", typeof(string)); receiveDocShortage.AddColumn("BatchNo", typeof(string)); receiveDocShortage.AddColumn("PalletLocationID", typeof(int)); receiveDocShortage.AddColumn("GUID", typeof(string)); } receiveDocShortage.SetColumn("FullItemName", receiveDoc.GetColumn("FullItemName")); receiveDocShortage.SetColumn("UnitName", receiveDoc.GetColumn("UnitName")); receiveDocShortage.SetColumn("ManufacturerName", receiveDoc.GetColumn("ManufacturerName")); receiveDocShortage.SetColumn("StockCode", receiveDoc.GetColumn("StockCode")); receiveDocShortage.SetColumn("ExpDate", receiveDoc.GetColumn("ExpDate")); receiveDocShortage.SetColumn("BatchNo", receiveDoc.GetColumn("BatchNo")); receiveDocShortage.SetColumn("GUID", receiveDoc.GetColumn("GUID")); receiveDocShortage.NoOfPacks = difference; } } else if (difference == 0 && receiveDocShortage.RowCount != 0) { RemoveFromDiscrepancy(guid); } if (receiveDocShortage.RowCount != 0) { grdDiscrepancy.DataSource = receiveDocShortage.DefaultView; } else { lcDiscrepancy.Visibility = LayoutVisibility.Never; } }