Visual Studio 2005
Visual Basic.net
Windows Application
I have a ListView, it is populated by a directory file list.
I change a filename, clear list, refresh and repopulate but it will not update.
My Method is the following:
User Starts program
User Selects a directory to work with
The ListView is populated with file names from the selected drirectory
The user enters search for text into a text box
The user enters replace text into a replace box
The User presses a "replace" button.
The List is updated with any changes.
Everything works except for the updating of the listview.
Form Load Code:
MyPath = "C:\testfolder\"
Dim dir As New DirectoryInfo(MyPath)
'Note: I have 4 listview colums set up in the design time columns collection if that makes a difference.
ListView1.View = View.Details
ListView1.FullRowSelect = False
For Each file As FileInfo In dir.GetFiles()
Dim item As New ListViewItem(file.Name)
item.SubItems.Add(file.Nam
e)
item.SubItems.Add(file.Las
tWriteTime
)
item.SubItems.Add(file.Cre
ationTime)
ListView1.Items.Add(item)
Next
Button Click:
ListView1.clear
' Replace Code
' and other stuff here
' Refresh the List view with newly named files of the selected directory.
ListView1.View = View.Details
ListView1.FullRowSelect = False
For Each file As FileInfo In dir.GetFiles()
Dim item As New ListViewItem(file.Name)
item.SubItems.Add(file.Las
tWriteTime
)
item.SubItems.Add(file.Cre
ationTime)
ListView1.Items.Add(item)
Next
When I run the the list view is blank.
If I do not use "ListView1.Clear" I just get the same items added to the ListView
so I know the code is working, but it is the ListView.Clear that is messing things up.
I assume I have to rebuild the ListView or something?
Maybe I am doing it wrong?
Start Free Trial