I used listview.. How to get the total value for each columnheader?
Printable View
I used listview.. How to get the total value for each columnheader?
Item (if this applies) + subitem1 + subitem2 = total_sum
If it's for each column wouldn't it be:
Listview.SubItem(1) + Listview.SubItem(2) = Total_Sum
I wasn't presenting syntax - only logic that's behind it. ;)
If someone's managed to load listview in the first place then he/she should be able to figure the correct syntax on their own.
Wouldn't you agree?
I do take things literally sometimes and I know how easily I get confused :lol:Quote:
Originally Posted by RhinoBull
It happends. :)Quote:
Originally Posted by aikidokid
The number of records is not limit only two records, How to sum the first records untill and the end of the records as I don't know the number of records exist in the listview
You'll have to loop through all columns and add each column's value to some variable. Then assign that total value to perhaps last column in your listview control.
Code:Private Sub Command1_Click()
Dim itm As MSComctlLib.ListItem
Dim subtotal As Single
Dim i As Integer
For Each itm In ListView1.ListItems
subtotal = Val(itm.Text) '<<< comment this if you don't need to calculate value of the item itself
For i = 1 To itm.ListSubItems.Count - 1
subtotal = subtotal + Val(itm.ListSubItems(i).Text)
Next i
itm.ListSubItems(itm.ListSubItems.Count).Text = susbtotal
subtotal = 0
Next itm
End Sub
What the used of this code ?
Only certain column I want to sum the value. I would like to sum each listitems for column1 and column 2Code:Private Sub Command1_Click()
Dim itm As MSComctlLib.ListItem
Dim subtotal As Single
Dim i As Integer
For Each itm In ListView1.ListItems
subtotal = Val(itm.Text) '<<< comment this if you don't need to calculate value of the item itself
For i = 1 To itm.ListSubItems.Count - 1
subtotal = subtotal + Val(itm.ListSubItems(i).Text)
Next i
itm.ListSubItems(itm.ListSubItems.Count).Text = susbtotal
subtotal = 0
Next itm
End Sub
In one of my projects, I need to do two columns. Here is my code for thatCode:For i = 1 To lvwIssues.ListItems.Count
'estimated impact amount
glngEstImpAmt = glngEstImpAmt + Val(lvwIssues.ListItems(i).SubItems(3))
'acutal impact amount
glngActImpAmt = glngActImpAmt + Val(lvwIssues.ListItems(i).SubItems(4))
'Debug.Print lvwIssues.ListItems(i).SubItems(4)
Next
matrik02,
Take a look at this quick example. You should be able to work this into your project :D
Thank you, that great 1:D