Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all
in datagridview i want sum values in a group another datagrid view

Can u help me*

What I have tried:

SUM2.PNG — Yandex.Disk[^]
Posted
Updated 31-May-20 21:38pm
v3
Comments
Maciej Los 1-Jun-20 2:05am    
Can you be more specific and provide more details about your issue?
You should explain what you mean by "group". The image does not show the groups.
Member 14588284 1-Jun-20 3:28am    
İ Added new image what i want
Thanks
Maciej Los 1-Jun-20 3:31am    
Please, use "Reply" widget (near the nick/login) to be sure that system will inform aout your reply.
Next time, please, copy-paste text data into the body of question.

Does your datagridview is bound with datasource?
Member 14588284 1-Jun-20 3:42am    
Ok.

1 solution

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim data = firstDgv.Rows.Cast(Of DataGridViewRow)() _
         .GroupBy(Function(r) New With {Key .A = r.Cells(0).Value, Key .B = r.Cells(1).Value}) _
         .Select(Function(grp) New With
         {
            grp.Key.A,
            grp.Key.B,
            .C = grp.Sum(Function(x) CInt(x.Cells(2).Value))
         }) _
         .ToList()

    For Each dgr In data
        secondDgr.Rows.Add(New Object() {dgr.A, dgr.B, dgr.C})
    Next
End Sub
 
Share this answer
 
v5
Comments
Member 14588284 1-Jun-20 3:55am    
Thanks for reply

How can i use this codes between two datagridview

first d.grid is data
second d.grid is sum group
Maciej Los 1-Jun-20 3:57am    
Does your datagridview "first" is bound with datasource?
Member 14588284 1-Jun-20 4:02am    
No,
i'm adding manuel
Maciej Los 1-Jun-20 4:36am    
See updated answer.
Member 14588284 1-Jun-20 5:10am    
i have an error on
r(0).Value, .B = r(1).Value}) _

https://yadi.sk/i/-imC8fRtg3d4GA

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