Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

[b] Can I total the items in a listview column? [/b]

Status
Not open for further replies.

Skorkpup

Programmer
Feb 17, 2005
11
I am using a listview in report view/mode. I would like to total up the cells in a paticular column to display in a textbox. I have no idea of how to go about doing this. any help would be appreciated.

Thanks,


Skorkpup
 
Try this function.
___
[tt]
Function GetTotal(LV As ListView, Column As Integer) As Variant
Dim N As Long
If Column = 1 Then
For N = 1 To LV.ListItems.Count
GetTotal = GetTotal + Val(LV.ListItems(N).Text)
Next
Else
For N = 1 To LV.ListItems.Count
GetTotal = GetTotal + Val(LV.ListItems(N).SubItems(Column - 1))
Next
End If
End Function[/tt]
___

And use it like this.

[tt]txtTotal = GetTotal(ListView1, 2)[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top