Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8388129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:24:07+00:00 2026-06-09T18:24:07+00:00

VS2010 C# .Net 4.1 I am working on a form that the user must

  • 0

VS2010 C# .Net 4.1

I am working on a form that the user must select or enter initial data in a ComboBox. Using the code below, which took some time to deduce, I enable the Edit button when the user hits the Tab key if the data is correct, otherwise the button is disabled it moves to the next button.

This code works, but a side effect is that the PreviewKeyDown event reoccurs when I set IsInputKey to true. This calls validation twice. The KeyDown event is only called once, and the IsInputKey is false again on the second call so I do need to check validation again.

I’d like to understand why and possibly avoid it.

private void comboBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { 
  if (e.KeyData == Keys.Tab) { 
    if (ValidationRoutine()) { 
      e.IsInputKey = true;  //If Validated, signals KeyDown to examine this key 
    } //Side effect - This event is called twice when IsInputKey is set to true 
  }           
} 

private void comboBox1_KeyDown(object sender, KeyEventArgs e) { 
  if (e.KeyData == Keys.Tab) { 
      e.SuppressKeyPress = true; //Stops further processing of the TAB key 
      btnEdit.Enabled = true; 
      btnEdit.Focus(); 
  } 
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T18:24:08+00:00Added an answer on June 9, 2026 at 6:24 pm

    The why? is hard to answer, Winforms just does. First from the message loop, again from the control’s message dispatcher. The event was really meant as an alternative way to implement the protected IsInputKey() method without having to override the control class. Bit of a hack, I always override and never used the event.

    The better mouse trap is to override ProcessCmdKey() instead. Like this:

        protected override bool ProcessCmdKey(ref Message msg, Keys keyData) {
            if (this.ActiveControl == comboBox1 && keyData == Keys.Tab) {
                if (ValidationRoutine()) {
                    btnEdit.Enabled = true;
                    btnEdit.Focus();
                    return true;
                }
            }
            return base.ProcessCmdKey(ref msg, keyData);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code written in .NET 4.0 using VS2010 Ultimate Beta 2: smtpClient.Send(mailMsg);
I'm working on a web-based academical evaluation project (VS2010,C#,ASP.NET). Users can enter the web
I'm working on my ASP.NET web project using VS2010, C#, I'm inserting a hyperlink
I'm working on an ASP.NET web projec using VS2010,C#, I want my users to
I'm working on an ASP.NET web project using VS2010/C#, I have some text boxes
I'm working on asp.net project using VS2010 . I want to share my project
I'm working on an ASP.NET web app in VS2010,C#. I've created a table for
I am using VS2010 C#.NET 3.5 and application settings (the Settings.settings file). What I
Using WPF .NET 4.0 in VS2010 RTM: I can't create a fullscreen WPF popup.
I have a ASP.NET MVC2 project in VS2010 that can be deployed in two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.