0
votes

The main task is to use values from one datagridview and have the sum be displayed on another datagridview on the same form. There will be two datagridviews on the same form

datagridview1

 apples | oranges 
      2 | 3
     10 | 20
      1 | 1

datagridview2

 total apples | total oranges
           13 | 24

is this at all possible? If not, I was thinking of possibly creating a new row in the original datagridview?

1
Loop through the rows and add the values together then add a row in the second DGV and put the sum there. Do you know how to do that? Give it a try and if there's a specific thing you can't figure out, we'll be happy to help. - 41686d6564
Thank you for the edit, I couldn't figure out how to make tables in the post. - user9990508
@AhmedAbdelhameed thank you for your suggestion. Yes, that seems simple enough, thank you! - user9990508
@AhmedAbdelhameed I was originally thinking of doing that .. the first part atleast. But I was not completely sure on how I would be able to "add a row in the second DGV to put the sum" .. will research - user9990508
One way to add a new row is: DataGridView2.Rows.Add(value1, value2). - 41686d6564

1 Answers

0
votes

Here's code to find the total of column index "1" for datagridview1 :

                Dim total As Double 'double or integer depends on your situation
                For i As Integer = 0 To DataGridView1.RowCount - 1
                    total += DataGridView1.Rows(i).Cells(1).Value
                Next

Now you need to add total to another datagridview:

                DataGridView2.Rows.Add("Oranges",total)