private void PopulateUsedInvoices() { //DataTable dtUsedInvoice = new DataTable(); dtUsedInvoice.Clear(); foreach (var column in dtUsedInvoice.Columns.Cast <DataColumn>().ToArray()) { if (dtUsedInvoice.AsEnumerable().All(dr => dr.IsNull(column))) { dtUsedInvoice.Columns.Remove(column); } } gridUsedSI.ItemsSource = null; dtUsedInvoice.Columns.Add("invoiceNo", typeof(string)); dtUsedInvoice.Columns.Add("invoiceQty", typeof(string)); dtUsedInvoice.Columns.Add("BalanceQty", typeof(string)); dtUsedInvoice.Columns.Add("invoiceAmt", typeof(string)); dtUsedInvoice.Columns.Add("BalanceAmt", typeof(string)); dtUsedInvoice.Columns.Add("TripNo", typeof(string)); foreach (DataRow dr in ClsPEZAData.GetPEZA8106itemDR(_formNo).Rows) { DataRow drw = dtUsedInvoice.NewRow(); drw["invoiceNo"] = dr["invoiceNo"].ToString().Trim(); drw["invoiceQty"] = Convert.ToDecimal(dr["invoiceQty"]).ToString("#,##0").Trim(); drw["BalanceQty"] = (Convert.ToDouble(tbEstimatedQuantity.Text == string.Empty ? 0 : Convert.ToDouble(tbEstimatedQuantity.Text.Replace(",", ""))) - Convert.ToDouble(dr["invoiceQty"])).ToString("#,##0"); drw["invoiceAmt"] = Convert.ToDecimal(dr["invoiceAmt"]).ToString("#,##0.00"); drw["BalanceAmt"] = (Convert.ToDouble(tbEstimatedAmount.Text == string.Empty ? 0 : Convert.ToDouble(tbEstimatedAmount.Text.Replace(",", ""))) - Convert.ToDouble(dr["invoiceAmt"])).ToString("#,##0.00"); drw["TripNo"] = dr["TripNo"].ToString().Trim(); dtUsedInvoice.Rows.Add(drw); } gridUsedSI.ItemsSource = dtUsedInvoice.DefaultView; }