I am rather new to VB and I am trying to figure out how I can do a certain routine. I am writing an archive program that has a checklistbox populated with all the directories on a certain drive. As the user checks on of the directories, it goes into a for loop that grabs the directory size and shows it on the form. But the issue that I am having is that once you start choosing more than 4 or 5 it gets slower and slower since it is reading through all the checkeditems and validating file size with. Is there a method for me to just grab last item checked or unchecked so i can just add/subtract from the current size? This my current code looping through all the checked items. Thank you in advance.
Dim fsize As Long = 0
Private Sub chklstbxWorkspace_SelectedIndexChanged(sender As Object, e As EventArgs) Handles chklstbxWorkspace.SelectedIndexChanged
Dim entry As Object
If chklstbxWorkspace.CheckedIndices.Count > 0 Then
btnStartArchive.Enabled = True
Else
btnStartArchive.Enabled = False
End If
lblWorkspaceSize.Text = chklstbxWorkspace.CheckedIndices.Count.ToString & " folders selected."
For Each entry In chklstbxWorkspace.CheckedItems
fsize += DirectorySize("w:\" & entry.ToString, True)
lblWorkspaceSize.Text = chklstbxWorkspace.CheckedIndices.Count.ToString & " folders selected. " & Format(fsize, "###,###,###,###,##0") & " bytes."
Next
Application.DoEvents()
End Sub