本文介绍了将列汇总到文本框中的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将列添加到文本框,其中是单元格中的值...在这种情况下单词Gotovina



我想念一些



需要帮助



我尝试过:



Sum column to textbox where is value in cell word...in this case word "Gotovina"

I miss somesthing

Need help

What I have tried:

////gotovina
           double[] columnData2 = new double[mp_kasa_listaDataGridView.Rows.Count];
           columnData2 = (from DataGridViewRow row in mp_kasa_listaDataGridView.Rows
                          where row.Cells["dataGridViewTextBoxColumn16"].FormattedValue.ToString() != string.Empty && (row.Cells["dataGridViewTextBoxColumn14"].ToString()) == ("Gotovina").ToString()// && System.DateTime.ParseExact("d.M.yyyy", row.Cells["dataGridViewTextBoxColumn4"].ToString(), System.Globalization.CultureInfo.InvariantCulture) == System.DateTime.Now.Date
                          select Convert.ToDouble(row.Cells["dataGridViewTextBoxColumn16"].FormattedValue)).ToArray();
           textBox3.Text = columnData2.Sum().ToString("#,0.00");

推荐答案

DataTable dt = (DataTable)mp_kasa_listaDataGridView.DataSource;
var result = dt.AsEnumerable()
    .GroupBy(x=>x.Field<string>("type"))
    .Select(grp=>new
    {
        PaymentType = grp.Key,
        Total = grp.Sum(x=>x.Filed<double>("price"))
    })
    .ToList();

foreach(var r in result)
{
    //display results 
}





对于特定交易类型:



For specific transaction type:

DataTable dt = (DataTable)mp_kasa_listaDataGridView.DataSource;
textBox1.Text = dt.AsEnumerable()
    .Where(x=>x.Field<string>("type")=="card")
    .Sum(x=>x.Field<double>("price"));





祝你好运!



Good luck!


这篇关于将列汇总到文本框中的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 09:32