• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

Updating listbox when file is deleted

I have a listbox (specifically a sunisoft file list box) that shows the files in a dir.  In my testing I've found that when I delete the files in the dir its pointed at using explorer, the list doesnt update

Should I use a timer?  that seems like an imperfect solution at best.   Any suggestions?
0
hibbidiji
Asked:
hibbidiji
  • 4
  • 2
  • 2
  • +3
2 Solutions
 
mikelittlewoodCommented:
Sounds like you need to do some sort of refresh method I guess.
Because your program doesnt actually delete the file itself, you will need to monitor it on a timer event I would think.
0
 
mikelittlewoodCommented:
I wonder if there is some sort of a windows message you could be polling for.
If you have 2 explorer windows open pointing to the same directory, and you delete a file from one, it automatically refreshes the other.
There might be a windows call somewhere here you could take advantage of.
0
 
hibbidijiAuthor Commented:
Thats what I'm hoping for (though I wouldnt know how to poll for the message even if we knew what it was)  :)

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mikelittlewoodCommented:
he he .. unfortunately neither do I, but hopefully my suggestion might be seen by someone who remembers how to do it and can give you the code.
I wish I knew more API stuff, but my knowledge in this area is pretty much non existant. Probably because I have no use for it these days.
0
 
mikelittlewoodCommented:
I found one possible link that might help

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_11428379.html

also do a search for "windows explorer refresh" here at EE. Might be a few more links that can help
0
 
ZhaawZSoftware DeveloperCommented:
I think TShellChangeNotifier (from 'Samples' tab) could help you to monitor some directory.
0
 
Mohammed NasmanSoftware DeveloperCommented:
Hello

Drop TShellChangeNotifier from Samples tab, set the Root property to the folder you would to monitor, then call update method of the FileListBox

procedure TForm1.ShellChangeNotifier1Change;
begin
  FileListBox1.Update;
end;

HTH

Regards,
Mohammed
0
 
Mohammed NasmanSoftware DeveloperCommented:
sorry ZhaawZ, I didn't see your comments when I open the questions
0
 
BigRatCommented:
I load files into my IDE but of course some idiot might edit or delete them outside. To monitor this, like Delphi does, I use a directory monitor. This sends me an event when anything changes in any of the directories from which I have loaded files. I'm currently using TDirMon (see Torry's pages) from Juan Carlos Molinos, which I've had to modify. There is another from Francois Piette which I have not yet tried out.

One problem I've found is that the components are very heavy, starting threads to pick up Windows events, but it does work.

I popup a message box saying that the file has changed and whether they want a reload. In your app, I'd popup a box warning of the change and then simply reload the list box.

HTH
0
 
BlackTigerXCommented:
check this thread
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21226302.html

there is a link to a unit that implements exactly what you need, something like a Directory Watcher, but without using a Timer
0
 
hibbidijiAuthor Commented:
Thanks guys.  Excellent answer.  worked first time
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now