Subscribe to Subscribers

Online Members

Kapil
More...

Resources » Code Snippets » Winforms DataGrid

How to add the values in several columns and give the result in another column of same row


Posted Date:     Category: Winforms DataGrid    
Author: Member Level: Silver    Points: 7



'Program is to How to add the values in several columns and
' give the result in another column of same row.

' If the DataGridView control has 4 columns and we want to add the values
' in the first three columns and display the Total in the last column
' of the same row.
' So, whenever a value in the column is changed the Total
' should get recalculated.


Private Sub DataGridView1_CellValidated(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValidated

Dim cy As Integer

'Get the current cell's Row
cy = DataGridView1.CurrentCellAddress.Y

' Add the first three columns (0,1,2) and display it in the
' fourth column
DataGridView1.Item(3, cy).Value = Val(DataGridView1.Item(0, cy).Value) + Val(DataGridView1.Item(1, cy).Value) + Val(DataGridView1.Item(2, cy).Value)

End Sub






Did you like this resource? Share it with your friends and show your love!


Responses to "How to add the values in several columns and give the result in another column of same row"

No responses found. Be the first to respond...

Feedbacks      

Post Comment:




  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Populating a Combobox in ASP from the Database
    Previous Resource: RowPostPaint Event
    Return to Resources
    Post New Resource
    Category: Winforms DataGrid


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Add column values in Data Grid  .  

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2013 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.