Results 1 to 5 of 5

Thread: sum of manually selected rows of datagridview

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2008
    Posts
    36

    Smile sum of manually selected rows of datagridview

    Hi all,

    I have a datagridview on my desktop application, what I need is to show in a a textbox the sum of collums values, of rows selected manually. Is this possible??????
    Can you guys help me on this?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: sum of manually selected rows of datagridview

    which columnIndex contains the numeric value?

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: sum of manually selected rows of datagridview

    try this (uses column 0):

    vb Code:
    1. Private Sub DataGridView1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.SelectionChanged
    2.     TextBox1.Text = (From row As DataGridViewRow In DataGridView1.Rows.Cast(Of DataGridViewRow)() _
    3.                      Where row.Selected = True _
    4.                      Select CInt(row.Cells(0).Value)).Sum.ToString
    5. End Sub

  4. #4
    Hyperactive Member Ram2Curious's Avatar
    Join Date
    Apr 2010
    Posts
    484

    Re: sum of manually selected rows of datagridview

    The DataTable.Compute Method might help.

  5. #5

    Thread Starter
    Member
    Join Date
    Jul 2008
    Posts
    36

    Resolved Re: sum of manually selected rows of datagridview

    Very good guys, it worked very well, thanks a lot.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width