Cancelling the Default button at run time -- VB.NET

Posted on 2009-02-24
Last Modified: 2012-06-21
Depending on the conditions, I want to change a button from being the Default button to not having a Default button at all.  I set the default button using this code:  
Me.AcceptButton = btnSearch
I tried cancelling this button with this code:
Me.AcceptButton = Nothing

but it still remains the default button.

Any suggestions?

Question by:lplasc
    LVL 27

    Accepted Solution

    Try programmatically setting the focus to another control after you set it to nothing:

            Me.AcceptButton = Nothing

    LVL 4

    Expert Comment

    Maker sure the DialogResult is set to NONE on the button.

    btnSearch.DialogResult = Windows.Forms.DialogResult.None

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    760 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

    7 Experts available now in Live!

    Get 1:1 Help Now