Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • *Experts*
Posted

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.

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted (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 by GreenKawasaki
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...