Click here to Skip to main content
15,884,821 members
Please Sign up or sign in to vote.
3.00/5 (1 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

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:
VB
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...
VB
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.
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900