如何在c#中的datagridview中找到两行的总和值 [英] How to find sum of two rows value inside the datagridview in c#

查看:272
本文介绍了如何在c#中的datagridview中找到两行的总和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将DataGridView中的两行值相加,并在DataGrid中创建一个新行并显示结果。

How to sum of two rows values inside the DataGridView, and create one new row in the DataGrid and display the result.

推荐答案

您需要获取字符串像这样的i-Row的值:

You need to get the string value of the i-Row like this:
string sValueOne = yourDataGridView.Rows[i].Cells[j].Value;



然后是下一行的值:


Then the value of the next row:

string sValueOne = yourDataGridView.Rows[i+1].Cells[j].Value;



现在你需要转换字符串to decimal / double / whatever and sum the values。



要添加新行,你可以这样做:


Now you need to convert the strings to decimal / double / whatever and sum the values.

To add new row you can do something like this:

DataGridViewRow row = (DataGridViewRow)yourDataGridView.Rows[i].Clone();
yourDataGridView.Rows.Add(row);


这篇关于如何在c#中的datagridview中找到两行的总和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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