OpenDialog behavior

Posted on 2012-09-06
Last Modified: 2012-09-07
I'd like to be able to select a file from an existing directory, so I set the OpenDialog's InitialDir to that known to exist directory. Subsequently, when the OpenDialog method is executed, how can I prevent users from browsing to other drives and directories?

I've set the option 'ofNoChangeDir' to true which apparently does not function.

OpenDialog2.InitialDir := DesiredDir;       // I want users tied to this directory
OpenDialog2.Filter := 'Text files|*.txt|';
if OpenDialog2.Execute then
   FileNameSelected.text := openDialog2.Files[0];

TIA - Ed
Question by:Ed-SSA
    LVL 19

    Expert Comment

    Use TFileOpenDialog events OnFolderChange and OnFolderChanging...
    Delphi OpenDialog without letting the user navigate away from the inital dir
    LVL 19

    Expert Comment

    TFileOpenDialog only available for Delphi versions 2009+
    LVL 19

    Expert Comment

    With TOpenDialog in older Delphi versions, you can try using CDM_HIDECONTROL for hiding the buttons to prevent folder change...
    LVL 25

    Assisted Solution

    by:Sinisa Vuk
    ... or you can create custom form with TShellListView (under sample tab) component and set custom folder to view it. This way you can have full control.

    Assisted Solution

    As I know, It is no way to restrict user browse within a folder. Maybe you can prompt a message and prevent the dialog close through event OnCanClose, or display a custom dialog with file list.
    LVL 19

    Accepted Solution

    Check this former EE post, which provides a solution for your problem...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Suggested Solutions

    Title # Comments Views Activity
    Printing problem 2 63
    maxMirror challenge 10 68
    Batch file output 20 71
    strCopies  challenge 17 60
    A short article about a problem I had getting the GPS LocationListener working.
    If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now