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 8458343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:03:14+00:00 2026-06-10T13:03:14+00:00

I have 25 textbox controls. The following code is for 2 textboxes only. So

  • 0

I have 25 textbox controls. The following code is for 2 textboxes only. So for 25 textboxes the code is going to be long, can I shorten the code?

 Private Sub TextBox_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles IDTextBox.KeyDown, DateDateTimePicker.KeyDown, ItemCodeTextBox.KeyDown, BrandTextBox.KeyDown, ItemTextBox.KeyDown
    If e.KeyCode = Keys.Enter And Me.IDTextBox.Focused Then
        Me.DateDateTimePicker.Focus()
    Else
        If e.KeyCode = Keys.Down And Me.IDTextBox.Focused Then
            Me.DateDateTimePicker.Focus()
        Else
            If e.KeyCode = Keys.Up And Me.DateDateTimePicker.Focused Then
                Me.IDTextBox.Focus()
            Else
                If e.KeyCode = Keys.Enter And Me.DateDateTimePicker.Focused Then
                    Me.ItemCodeTextBox.Focus()
                Else
                    If e.KeyCode = Keys.Down And Me.DateDateTimePicker.Focused Then
                        Me.ItemCodeTextBox.Focus()
                    Else
                        If e.KeyCode = Keys.Up And Me.ItemCodeTextBox.Focused Then
                            Me.DateDateTimePicker.Focus()
                        End If
                    End If
                End If
            End If

        End If
    End If

End Sub
  • 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-10T13:03:15+00:00Added an answer on June 10, 2026 at 1:03 pm

    Use can make your code clean using “Select Case” instead of ‘If’ condition.
    This would be much cleaner. see this link

    @Farook…… Try this

    Private Sub Form1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
        Select Case True
            Case (e.KeyCode = Keys.Down And Me.ActiveControl.GetType IsNot GetType(DateTimePicker))
                    Me.SelectNextControl(Me.ActiveControl, True, True, True, True) 'forwards
            Case (e.KeyCode = Keys.Enter And Not (Me.ActiveControl.GetType Is GetType(TextBox) AndAlso DirectCast(Me.ActiveControl, TextBox).Multiline))
                Me.Text = Me.SelectNextControl(Me.ActiveControl, True, True, True, True).ToString  'forwards
            Case (e.KeyCode = Keys.Up And Me.ActiveControl.GetType IsNot GetType(DateTimePicker))
                Me.SelectNextControl(Me.ActiveControl, False, True, True, True)  'backwards
        End Select
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code in my DataGridTemplateColumn: <Controls:DataGridTemplateColumn.CellEditingTemplate> <DataTemplate> <StackPanel Orientation=Horizontal> <TextBox Text={Binding
I am using the following code to create calendar controls on textboxes that have
I have the following textbox server control in my web page: <asp:TextBox ID=txtZip runat=server
I have a TabControl with TextBox controls in the ContentTemplate . When I type
I have: Textbox(Multi-line) Panel Different controls inside panel (buttons,textbox) Scenario: I need to add
I have a few asp:textbox controls in a form on a webpage, below is
I have two user controls, in one of them I have a textbox, i
I have few controls (Label, Custom Textbox, Datagridview) docked on a form. When I
I have a Form with multiple different controls like ComboBox , TextBox and CheckBox
This is going to be a long post. I would like to have suggestions

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.