I create a project on vb.net 2010 and SQL server 2008r2 I showing a report in listview report am show fine and error free. But now I want to add a sub total column every end of the category. How it is possible please help me sir

Please see the attachment picture

https://ibb.co/tZ86Hvb

https://ibb.co/V22d4Sk

I try many coding, but not work, because i have no more knowledge about this.
And search on google but many example are on Datagridview, but I used Listview
please help me sir.......

Dani AI

Generated

As suggested, the simplest route is to insert a subtotal as a normal ListViewItem for each category while building the ListView. ListView (Details view) has no built‑in footer/subtotal feature like DataGridView, so either compute totals in SQL and return rows that include subtotals, or compute totals client‑side while populating ListView1 and insert a styled subtotal item after each category. The OP noted VB.NET 2010 + SQL Server 2008R2, so both approaches are viable.

A straightforward client‑side algorithm (build sorted data, walk rows, accumulate, add subtotal item when category changes) — example VB.NET pattern:

' dt: DataTable with columns "Category","Item","Amount"
ListView1.Items.Clear()
Dim lastCat As String = Nothing
Dim subtotal As Decimal = 0D

For Each dr As DataRow In dt.Rows
    Dim cat = dr("Category").ToString()
    Dim amt = Convert.ToDecimal(dr("Amount"))
    If lastCat Is Nothing Then lastCat = cat
    If cat <> lastCat Then
        Dim s As New ListViewItem("Subtotal for " & lastCat)
        s.SubItems.Add("") : s.SubItems.Add(subtotal.ToString("N2"))
        s.BackColor = Color.LightGray
        s.Font = New Font(ListView1.Font, FontStyle.Bold)
        ListView1.Items.Add(s)
        subtotal = 0D : lastCat = cat
    End If
    Dim it As New ListViewItem(cat)
    it.SubItems.Add(dr("Item").ToString()) : it.SubItems.Add(amt.ToString("N2"))
    ListView1.Items.Add(it)
    subtotal += amt
Next
If lastCat IsNot Nothing Then
    Dim s As New ListViewItem("Subtotal for " & lastCat)
    s.SubItems.Add("") : s.SubItems.Add(subtotal.ToString("N2"))
    s.BackColor = Color.LightGray
    s.Font = New Font(ListView1.Font, FontStyle.Bold)
    ListView1.Items.Add(s)
End If

SQL can also return detail + subtotal rows using a UNION, which offloads the aggregation to the server and makes the client code simpler. Example pattern:

SELECT Category, ItemName, Amount, 0 AS IsSubtotal FROM Items
UNION ALL
SELECT Category, 'Subtotal', SUM(Amount), 1 FROM Items GROUP BY Category
ORDER BY Category, IsSubtotal ASC, ItemName;

Notes and troubleshooting: ensure the data is sorted by Category before iterating or disable ListView.Sorting so subtotal rows stay next to their group. If ListView.VirtualMode or custom sorting is used, insert subtotal logic into the virtual provider or implement a comparer that treats subtotal items specially. For a more report‑like layout (fixed footers, multi‑column formatting), consider a UserControl or ReportViewer as hinted.

Fiestly please show the code what you did.

Secondly, for every catagory at the end the subtotals should be added as a listitem for that catagory. Or you have to create an User Control for your use.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.