Click here to Skip to main content
15,891,904 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have already set up the datatables and everyhing.
I just want to display the data into a more friendly version fro the users.
Is it possible to have a result like this:

col1      col2
group1 subheading
 A                  100
 B                  200
group1 ttl          300
group2 subheading
 A                  50
 B                  20
group2 ttl          70





'CHA
Posted
Updated 23-Feb-15 14:17pm
v2
Comments
PIEBALDconsult 23-Feb-15 20:16pm    
Everything is possible.
http://www.codeproject.com/Tips/356267/Sorting-Total-after-data-values
Member 11474032 23-Feb-15 23:00pm    
thanks, it really is helpful but I gave the wrong question, it should be:
the total is the sum of per group column 2 and not the count of same row value.

col1 col2
group1 subheading
A 100
B 200
group1 ttl of col2 300 ---------------'SUM OF GROUP 1
group2 subheading
A 50
B 20
group2 ttl of col2 70 '-----------------SUM OF GROUP 2

if it is possible,
thank YOU :)

1 solution

See if this is what your looking for, I created a blank form, added a datagrid and 2 labels:

VB
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    DataGridView1.Rows.Add("Item 1", "SAW", "20")
    DataGridView1.Rows.Add("Item 2", "CHAIN", "50")
    DataGridView1.Rows.Add("Item 1", "WOOD", "60")
    DataGridView1.Rows.Add("Item 4", "BENCH", "10")

    'total values from the datagrid
    Dim xMC, xAC As Decimal
    For Each row As DataGridViewRow In DataGridView1.Rows
        If row.Cells(0).Value = "Item 1" Then
            xMC += row.Cells(2).Value 'Adds each column of ITEM 1 and totals
        End If
        If row.Cells(0).Value = "Item 2" Then
            xAC += row.Cells(2).Value 'Adds each column of ITEM 2 and totals
        End If

    Next

    'displays the results
    Label1.Text = "ITEM 1 Cost: " & "$" & String.Format("{0:n0}", Math.Round(xMC, 2))
    Label2.Text = "ITEM 2 Cost: " & "$" & String.Format("{0:n0}", Math.Round(xAC, 2))


End Sub
 
Share this answer
 

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