对两个datagridview单元格求和 [英] sum on two datagridview cells

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

问题描述

我有一个问题是在两个datagridview单元格上执行求和(作为两个矩阵),就像:

dataGridView5.Rows [2] .Cells [i] .Value = dataGridView5.Rows [2 ] .Cells [i] .Value + dataGridView5.Rows [2] .Cells [i-1] .Value



erorr是operator'+'不能是应用于'对象'和'对象'类型的操作数

plz帮助我解决这个问题.tnx

I have a problem to perform sum on two datagridview cells(as two matrix),just like:
dataGridView5.Rows[2].Cells[i].Value=dataGridView5.Rows[2].Cells[i].Value+dataGridView5.Rows[2].Cells[i-1].Value

the erorr is "operator'+' cannot be applied to operands of type'object'and 'object' "
plz help me to solve this problem.tnx

推荐答案

在下面尝试,转换为int(我假设你有整数值)并取总和



try below, convert to int ( I assume you have integer values) and take the sum

dataGridView5.Rows[2].Cells[i].Value=Convert.ToInt32(dataGridView5.Rows[2].Cells[i].Value.ToString())+Convert.ToInt32(dataGridView5.Rows[2].Cells[i-1].Value.ToString())


在对这些值求和之前,将这些值转换为数值类型(整数或十进制)。
Convert these values into numeric types (integer or decimal) before doing a sum on these values.


使用单元格的Te xt属性并将其转换为整数。



Use the cell's Text property and convert it to Integer.

dataGridView5.Rows[2].Cells[i].Value=Convert.ToInt32(dataGridView5.Rows[2].Cells[i].Text)+Convert.ToInt32(dataGridView5.Rows[2].Cells[i-1].Text) 


这篇关于对两个datagridview单元格求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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