在通过ADVG数据网格过滤后,我尝试对列中的值求和,但是添加的行未出现在网格中。
我该如何解决问题?
private DataTable SumDataInColInGrid(DataGridView dtgrid)
{
DataTable dt = new DataTable();
dt = dtgrid.DataSource as DataTable;
DataRow dr = dt.NewRow();
int sum = 0;
for (int i = 0; i < dt.Columns.Count; i++)
{
if (dt.Columns[i].ColumnName.ToUpper() == "TOTALQTY")
{
for (int j = 0; j < dtgrid.Rows.Count; j++)
{
if (!string.IsNullOrEmpty(dtgrid.Rows[j].Cells[i].Value.ToString()))
sum += int.Parse(dtgrid.Rows[j].Cells[i].Value.ToString());
}
dr[i] = sum.ToString();
dt.Rows.Add(dr);
break;
}
}
dtgrid.DataSource = dt;
return dt;
}