FileListBox not updating

Status
Not open for further replies.

bjwade62

Well-known member
Joined
May 25, 2006
Messages
50
Programming Experience
3-5
I'm using System.IO.File.Copy to copy a file to a folder. I have a FileListBox on my form that contains the files in that folder. The problem I'm having is that the FileListBox doesn't show the newly added file unless I change folders and then come back it.
I've tried FileListBox.Refresh and FileListBox.Update with no luck.
Any help out there?
Thanks,
Bernie
 
Here's some simple code to populate the files to Listbox, you can call this code each time you want it to 'refresh' the list of files.
VB.NET:
Expand Collapse Copy
Dim folderpath As New IO.DirectoryInfo("C:\")
ListBox1.DataSource = folderpath.GetFiles("*.txt")
ListBox1.ValueMember = "Name"
Given circumstances you could also use a FileSystemWatcher to monitor this folder and automatically 'refresh' Listbox with this code when files in that folder changes.
 
I'm not sure why? JohnH made no mention that the refresh code should be done inside of a SelectedIndexChanged event though you are correct in pointing out (implicitly) that such a move would not be wise...
 
Last edited by a moderator:
Status
Not open for further replies.
Back
Top