对datagridView中的选定单元格求和时的小问题 [英] Little Problem When Summing Selected cells in datagridView

查看:104
本文介绍了对datagridView中的选定单元格求和时的小问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
对dataGridView中的选定单元格求和时我没有什么问题
在网格是大量串的不同之处在于当细胞被选择DGV品牌错误小数.我该怎么做,以便如果选择的字符串包含在内,请不要进行任何更改.
谢谢.
顺便说一句,有人可以建议我如何只留下两位数字的下一个点吗?圆的
再次感谢
这是我的代码:


Hello Guys
I have little problem when summing selected cells in dataGridView
In grid is lots of strings except decimals when that cells are selected dgv makes error. how can i make so that if selected is contains strings dont make any changes.
Thanks.
By The Way can anyone advice me how to how leave only two digits next dot? and round
Thanks once again
Here is my code:


private void dataGridView1_SelectionChanged(object sender, EventArgs e)
{
    decimal nextNumber = 0;
    decimal sumNumbers = 0;
    for (int i = 0; i < dataGridView1.SelectedCells.Count; i++)
    {
        nextNumber = Convert.ToDecimal(dataGridView1.SelectedCells[i].FormattedValue.ToString());
        sumNumbers += nextNumber;
    }
    tlblPriceTotal.Text = "Sum: " + sumNumbers.ToString();
    tlblSelectedCellsTotal.Text = "TotalSelected: " + dataGridView1.SelectedCells.Count.ToString();

>
}


}

推荐答案

您遇到什么错误?

对于四舍五入,请在此处 [ ^ ] .
What error are you getting?

For rounding off, have a look here[^].


这篇关于对datagridView中的选定单元格求和时的小问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆