在vb.net的特殊单元格中获取和 [英] get sum in special cell in vb.net

查看:91
本文介绍了在vb.net的特殊单元格中获取和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在datagrid的两个单元格中求和.单元格是(2,3)&(3.5)
请在文本框中显示使用vb.net 2008.sum的pleace helpme.im.知道如何从DataGridView获取单元格.问题是单元格包含Object.而且您不能添加Object s.
如果确定单元格(2,3)和(3,5)始终存在并且始终用数字类型填充,则可以简单地执行以下操作:

  Dim  var  As  十进制 =  CDec (dgvMyGrid.Item( 2  3 ).Value)+  CDec (dgvMyGrid.Item( 3  5 ).值)
txtMyTextBox.Text = var.ToString 


如果值为Integer,则可以使用CInt.可以安全地检查该单元格是否存在...

 如果 dgvMyGrid.Item( 2  IsNot   AndAlso  dgvMyGrid.Item( 3  5 )是不是 什么都没有 然后
   ' 与上述代码相同.请注意,如果单元格的值为Nothing,则CDec将返回0.
结束 如果 


希望有帮助.


i need get sum in two cell in datagrid. cells are (2,3) &(3.5)
pleace help me.im using vb.net 2008.sum should be display in text box.pls guy,pls help me.tax!

解决方案

Well, you seem to know how to get the cell from a DataGridView... The problem is that a cell holds an Object. And you can''t add Objects.
If you''re sure cells (2, 3) and (3, 5) always exist and are always filled with a numeric type you could simply do the following:

Dim var As Decimal = CDec(dgvMyGrid.Item(2, 3).Value) + CDec(dgvMyGrid.Item(3, 5).Value)
txtMyTextBox.Text = var.ToString


If the values are Integers you could use CInt. It would be safe to check if the cell exist though...

If dgvMyGrid.Item(2, 3) IsNot Nothing AndAlso dgvMyGrid.Item(3, 5) IsNot Nothing Then
   ' Same code as above. Notice that if the value of the cell is Nothing CDec will return 0.
End If


Hope that helps.


这篇关于在vb.net的特殊单元格中获取和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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