VB.NET - 是否可以计算分组行的数据并将计算放在分组数据下面? [英] VB.NET - Is it possible to compute data of grouped rows and put the computation below the grouped data?

查看:101
本文介绍了VB.NET - 是否可以计算分组行的数据并将计算放在分组数据下面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经设置了数据表和每个人。

我只想将数据显示为一个更友好的版本给用户。

是否可以得到这样的结果:



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






'CHA

推荐答案

看看这是否是你要找的,我创建了一个空白表格,添加了一个数据网格和2个标签:



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

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: " & "


& 字符串 .Format( {0:n0},Math.Round(xMC, 2 ))
Label2.Text = 第2项费用:&
" & String.Format("{0:n0}", Math.Round(xMC, 2)) Label2.Text = "ITEM 2 Cost: " & "


& 字符串 .Format( {0:n0},Math.Round(xAC, 2 ))


End Sub
" & String.Format("{0:n0}", Math.Round(xAC, 2)) End Sub


这篇关于VB.NET - 是否可以计算分组行的数据并将计算放在分组数据下面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆