Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Enter Key as Tab Key For Next Control Multiline Issue

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
VS 2008. Trying to use Enter Key as Tab Key to move to next control. This works well except ctl is always returning tsc1, my tool strip container as the active control no matter which control I'm on. So the multiline section never gets executed.
Code:
 Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
    Dim dotab = False
    Dim ctl = Me.ActiveControl
    If ctl IsNot Nothing And keyData = Keys.Enter Then
      dotab = True
      If TypeOf ctl Is TextBoxBase Then
        If DirectCast(ctl, TextBoxBase).Multiline Then dotab = False
      End If
    End If
    If dotab Then
      If Me.SelectNextControl(ctl, True, True, True, True) Then Return True
    End If
    Return MyBase.ProcessCmdKey(msg, keyData)
  End Function


Auguy
Sylvania/Toledo Ohio
 
OK, I think I got it to work even with my data grid view to send a Tab Key to move to next cell.
Code:
  Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
    If keyData = Keys.Enter Then
      Dim dotab = True
      Dim ctl = Me.ActiveControl

      If ctl.GetType() Is GetType(ToolStripContainer) Then
        Dim rob As ToolStripContainer = DirectCast(ctl, ToolStripContainer)

        Dim ctl2 As New Control
        ctl2 = rob.ActiveControl

        If ctl2.GetType() Is GetType(SplitContainer) Then
          Dim rob2 As SplitContainer = DirectCast(ctl2, SplitContainer)
          Dim ctl3 As New Control
          ctl3 = rob2.ActiveControl

          If ctl3.GetType() Is GetType(TextBox) Then
            If DirectCast(ctl3, TextBoxBase).Multiline Then dotab = False
          Else
            If ctl3.GetType().ToString.Contains("DataGridView") Then
              SendKeys.Send("{Tab}")
              Return True
            End If
          End If

          If dotab Then
            If Me.SelectNextControl(ctl3, True, True, True, True) Then Return True
          End If

        ElseIf ctl2.GetType() Is GetType(TextBox) Then
          If Me.SelectNextControl(ctl2, True, True, True, True) Then Return True
          Return True
        End If
      End If
    End If
    Return MyBase.ProcessCmdKey(msg, keyData)
  End Function

Auguy
Sylvania/Toledo Ohio
 
Any comments would be great. I will try and generalize it a bit more if possible.

Auguy
Sylvania/Toledo Ohio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top