Results 1 to 4 of 4

Thread: Is there a way to disable "Cancle" on OpenFileDialogs and SaveFileDialogs?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2011
    Posts
    88

    Is there a way to disable "Cancle" on OpenFileDialogs and SaveFileDialogs?

    I have some code that runs on "Ok" for OpenFileDialogs and SaveFileDialogs.
    If the user presses cancle without selecting something, the program crashes and gives me a headache because it sets off a chain reaction that I won't get into detail about.

    So is there a way to make it so that "Cancle" is grayed out or something on the Dialog Boxes?

    If not, is there an alternative that could solve this problem?

    Edit: The code that causes the crash (and subsequent headache) doesn't run directly from the "Ok" action
    Last edited by Lucien Montierre; Oct 5th, 2011 at 10:15 PM. Reason: Extra Detail

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Is there a way to disable "Cancle" on OpenFileDialogs and SaveFileDialogs?

    how are you calling it? You do know that the ShowDialog method will return the a DialogResult that will tell you if they clicked, OK, Save, Open or Cancel...

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim MyDialog As New ColorDialog()
        ' Keeps the user from selecting a custom color.
        MyDialog.AllowFullOpen = False
        ' Allows the user to get help. (The default is false.)
        MyDialog.ShowHelp = True
        ' Sets the initial color select to the current text color,
        MyDialog.Color = TextBox1.ForeColor
    
        ' Update the text box color if the user clicks OK 
        If (MyDialog.ShowDialog() = Windows.Forms.DialogResult.OK) Then
            TextBox1.ForeColor = MyDialog.Color
        End If
    End Sub
    Documentation: http://msdn.microsoft.com/en-us/libr...t40c.aspx#Y357

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Is there a way to disable "Cancle" on OpenFileDialogs and SaveFileDialogs?

    Do you really think that preventing the user from not choosing a file would be the best solution? What if the file they want doesn't exist? Should they just leave your program running with the dialogue showing indefinitely?

    There are two ways to handle a OFD or SFD. You can do as tg has shown and test the value returned by ShowDialog, or you can handle the FileOK event. In both cases, your code will not be executed unless the user clicks OK. Unless your system is corrupt in some way, you must simply not be writing the code correctly. As you haven't shown us the code, we can only guess at what the problem might be.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2011
    Posts
    88

    Re: Is there a way to disable "Cancle" on OpenFileDialogs and SaveFileDialogs?

    vb Code:
    1. If (MyDialog.ShowDialog() = Windows.Forms.DialogResult.OK) Then
    2.      
    3.     End If

    Did the trick, thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width