标签:
Clipboard.Clear(); Dictionary<string, decimal> dtary = new Dictionary<string, decimal>(); string Ls = ""; foreach (int i in gridView1.GetSelectedRows()) { var da = gridView1.GetRow(i); //GridView gv = gridView1; //if (dr != null) foreach (GridColumn j in gridView1.GetSelectedCells(i)) { decimal num = 0.00m; string columnNum = ""; foreach (PropertyInfo pi in da.GetType().GetProperties()) { if (pi == null) continue; if (pi.CanWrite == false) continue; if (pi.GetValue(da, null) != null) if (pi.Name == j.FieldName) { try { columnNum = pi.GetValue(da, null).ToString(); } catch { } } } Ls += columnNum + "\t"; if (decimal.TryParse(columnNum, out num)) { if (dtary.ContainsKey(j.Name)) dtary[j.Name] += num; else dtary[j.Name] = num; } //var a = j.Column.Name; } Ls += "\r"; } Clipboard.SetDataObject(Ls); string returnmsg = "所有选中列可以统计的统计情况为:"; foreach (KeyValuePair<string, decimal> vkp in dtary) { returnmsg += "\n" + vkp.Key + "列値为:" + vkp.Value.ToString(); } MessageBox.Show(returnmsg);
以上包含复制选中的不包含列头的输出。与统计可统计的所有选中行。需要固定统计数据源为数字类型的。另外联系我就行了
标签:
原文地址:http://www.cnblogs.com/gclearn/p/4513590.html