C#_datagridview 增加一行统计

来源:互联网 发布:小霸王软件下载 编辑:程序博客网 时间:2024/05/24 02:15

String projectfliter=null;

privatevoid toolStripComboBox2_DropDownClosed(object sender, EventArgs e)

{

projectfliter = toolStripComboBox2.SelectedItem.ToString();

DataSet da =newDataSet();

da.ReadXml("Your Data Source Local");

DataView dv = da.Tables[0].DefaultView;

dv.RowFilter = string.Format("ProjectName='{0}'", projectfliter.ToString());

dataGridView1.DataSource = da.Tables[0].DefaultView;

int count = dataGridView1.RowCount;

Double text = 0;

for (int b = 0; b < count; b++)

{

string value =Convert.ToString(dataGridView1.Rows[b].Cells[2].Value);

if (!string.IsNullOrEmpty(value))

{

text += Double.Parse(value);

}

}

uhours = text.ToString();

dataGridView1.DataSource = 0;

System.Data.DataTable dt =new System.Data.DataTable();

dt = dv.ToTable();

DataRow dr = dt.NewRow();

dr[0] = " ";

dr[1] = "Totals:";

dr[2] = uhours;

dt.Rows.Add(dr);

uhours = null;

dataGridView1.DataSource = dt;

 

}

 

原创粉丝点击