How do I get the SuspendLayout and ResumeLayout to work correctly in regards to a listview. I have added these lines of code before and after I have added the items, yet each item is still being displayed as I add each item.
thanks
-
My code:
Dim x As Integer Dim startTick As Integer = Environment.TickCount lstFiles.SuspendLayout() For x = 0 To UBound(cacheListArray) If cacheListArray(x) Like "*.txt" Then lstFiles.Items.Add(cacheListArray(x)) End If Next lstFiles.ResumeLayout() MsgBox(Environment.TickCount - startTick)
I am adding 2000 items. This takes 7 seconds. I was told that it should be a lot shorter than that. Is that correct?
New code:
Dim ListViewItemArray(-1) As ListViewItem
ReDim Preserve ListViewItemArray(UBound(ListViewItemArray) + 1)
ListViewItemArray(UBound(ListViewItemArray)).Text = file.Name
ListViewItemArray(UBound(ListViewItemArray)).SubItems.Add(file.FullName)
ListViewItemArray(UBound(ListViewItemArray)).SubItems.Add(file.Length)
ListViewItemArray(UBound(ListViewItemArray)).SubItems.Add(file.CreationTime)
ListViewItemArray(UBound(ListViewItemArray)).SubItems.Add(file.LastWriteTime)
ListViewItemArray(UBound(ListViewItemArray)).SubItems.Add(file.LastAccessTime)
lstFiles.Items.AddRange(ListViewItemArray)
Nothing is being added. What have I done incorrectly?
You are using the wrong method. The Suspend/ResumeLayout() methods are only appropriate for container controls whose child controls you want to move around without them getting repainted while you are doing so. You never give ListView any child controls.
Use the Begin/EndUpdate() methods instead.