Click here to Skip to main content
14,331,758 members
Rate this:
Please Sign up or sign in to vote.
See more:
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!
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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.
   
v2
Comments
Amal anjula 29-Jan-12 21:55pm
   
Thanks u lot! its worked!
Sander Rossel 30-Jan-12 2:33am
   
Glad it helped! Now don't forget to accept the answer that helped you :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100