Shovan Saha

Shovan Saha

  • NA
  • 321
  • 91.8k

Datagridview Count Problem

Aug 5 2017 1:47 PM
I am new in code. Below is a sample, here sumOthers gives me fine result but countOthers does not give me the correct result. Please help me. Here is my code:
 
var countTotal = Convert.ToInt32(count1 + count2 + count3);
double sumTotal = Convert.ToDouble(sum1 + sum2 + sum3);
var count220 = 0;
foreach (DataGridViewRow g1 in dataGridView1.Rows)
{
if (g1.Cells[5].Value.ToString() != "" && g1.Cells[5].Value.ToString() != null)
count220 = count220 + Convert.ToInt32(g1.Cells[5].Value);
}
double sum220 = 0;
foreach (DataGridViewRow g1 in dataGridView1.Rows)
{
if (g1.Cells[5].Value.ToString() != "" && g1.Cells[5].Value.ToString() != null)
sum220 = sum220 + Convert.ToDouble(g1.Cells[5].Value);
}
var countOthers = count220 - countTotal;
double sumOthers = sum220 - sumTotal;
PdfPCell NoOfRemittance220 = new PdfPCell(new Phrase(countOthers.ToString()));
NoOfRemittance220.Colspan = 2;
NoOfRemittance220.HorizontalAlignment = Element.ALIGN_CENTER;
table.AddCell(NoOfRemittance220);
PdfPCell AmountBDT220 = new PdfPCell(new Phrase(sumOthers.ToString()));
AmountBDT220.Colspan = 3;
AmountBDT220.HorizontalAlignment = Element.ALIGN_RIGHT;
table.AddCell(AmountBDT220);

Answers (1)