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
Use can make your code clean using “Select Case” instead of ‘If’ condition.
This would be much cleaner. see this link
@Farook…… Try this