GreenKawasaki Posted December 24, 2003 Posted December 24, 2003 Hello, I have a listview with a bunch of files with their size. When I select items I want the total of the file sizes to show up in the statusbar. The problem is that when i select and deselect files like over 300, the SelectedIndexChanged event gets called every time, like 300..299..298 when you deselect all files, and the statusbar size gets updated very slowly. Is there any way to total first and only update the statusbar after all the math is done. Thanks, VB Newbie Quote
*Experts* DiverDan Posted December 24, 2003 *Experts* Posted December 24, 2003 It sounds like you are summing up the file sizes and updating the status bar in the same loop. Try only adding the file sizes in the loop, then add an Application.DoEvents line after the line following End Next. Finally post the file size summation to the status bar. Dim i, fileSizeTotal as Integer For i = 0 to ListView1.Items.Count - 1 fileSizeTotal += Val(ListView1.Items(i).SubItems('?').Text) '?' is the listview column index where the file sizes are listed - remember the first column is #0 End Next Application.DoEvents StatusBar1.Text = "Total File Sizes : " & fileSizeTotal Application.DoEvents forces VB to complete the prior computations before proceeding. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
GreenKawasaki Posted December 25, 2003 Author Posted December 25, 2003 (edited) Thanks DiverDan for the help! Unfortunately your tip didn't help. I originally never had the statusbar update in the loop but outside. My code is as follows: Private Sub ListView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged Dim Count As Integer = 0, Size As Single = 0 Dim Item As ListViewItem Dim MyItems As ListView.SelectedListViewItemCollection MyItems = Me.ListView1.SelectedItems For Each Item In MyItems Count = Count + 1 Size = Size + Int(Item.SubItems(3).Text) / 1000 Next StatusBarPanel2.Text = "Selected " & Count & " File(s), " & Size.ToString() & " " & "KB" End Sub Still, if I have like 300 items in my listview, the statusbar gets updated at every iteration like 299..298.297.. and is really slow. Any more help. I figured a way to cheat by having a timer just update the statusbar at every tick. But I don't think thats a good use of system resources. Any more ideas? Thanks a lot! Sincerely, VB Newbie Edited December 25, 2003 by GreenKawasaki Quote
FartNocker Posted December 26, 2003 Posted December 26, 2003 Why not do it in a click event? then you don't have to worry about all that... Quote
GreenKawasaki Posted December 26, 2003 Author Posted December 26, 2003 Hi, I don't want to do it in a click event because I want the list to be updated automatically as you select items without letting go of the mouse button. This is so the user can see how many items he's selected before letting go of the mouse button. I want it to work like Windows explorer when you drag around and select items. VB newbie Quote
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.