simple Posted May 13, 2005 Posted May 13, 2005 Hello. I need someones help. I need to find the total of column 5 (Balance) in my listview control. the total should go in txtTotalValue.text BTW I have this...but its not working..(in red).. Private Sub frmSummary_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim lastName As String Dim count As Integer count = 0 For Each lastName In colLastName count += 1 Dim lviItem As New ListViewItem(lastName) lviItem.SubItems.Add(colFirstName.Item(count)) lviItem.SubItems.Add(colAccountNumber.Item(count)) lviItem.SubItems.Add(colAccountStatus.Item(count)) lviItem.SubItems.Add(Format$(colBalance.Item(count), "Currency")) lstList.Items.Add(lviItem) Next Dim intIndex As Integer Dim intListCount As Integer Dim strBalance As String, intBalance As Integer Dim intTotalValue As Integer intListCount = Convert.ToInt32(lstList.Items.Count) For intIndex = 0 To intListCount - 1 strBalance = lstList.Items(intIndex).SubItems(4).Text strBalance = strBalance.Replace("$", "0") intBalance = Convert.ToInt32(strBalance) intTotalValue += intBalance Next txtTotalValue.Text = Format$(intTotalValue, "Currency") txtNoRecords.Text = count Thank you in advance. Quote
*Experts* DiverDan Posted May 14, 2005 *Experts* Posted May 14, 2005 (edited) I'm a bit confussed. what is colLastName, colFirstName, etc? Are you wanting to load the listview from a structured ArrayList or a number of separate arrays? My opinion only would to setup a structured ArrayList with FirstName, LastName, AccountNumber, AccountStatus, etc. Then load the listview from the ArrayList. Structure structAccount Dim LastName, FirstName, AccountNumber as String Dim Balance as Integer 'Double would be better for decimal numbers End Structure Dim Accounts as New ArrayList Dim newAccount as new structAccount With newAccount .FirstName = ? .LastName = ? .AccountNumber = ? .Balance = ? Accounts.Add(newAccount) Next Dim Account as structAccount For Each Account In Accounts With ListView1.Items.Add(Account.FirstName) .SubItems.Add(Account.LastName) .SubItems.Add(....) Next Dim i as Integer Dim Balance As Double = 0 For i = 0 to ListView.Items.Count - 1 Balance += CDbl(ListView.Items(i).SubItems(4).Text) Next The record count would now be Accounts.Count ...or something similar Edited May 14, 2005 by DiverDan Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.