Resolved Remove Tab Index Funcitonality From Left/Right Arrows

rcombs4

Well-known member
Joined
Aug 6, 2008
Messages
189
Programming Experience
3-5
I think i'm just having an off day but for the live of me I can't come up with a solid way of explaining what I want to do. So here goes.

Im building a, lets say kiosk, that has only one form of input and that is a keyboard. I've got an up/down/left/right arrows and the enter button. I have a form that needs to have hundreds of buttons. I've arranged all my buttons in a giant grid and want the user to use the arrows to navigate through the buttons. The button that is 'highlighted', lack of a better term, has different colors so we know which button we currently are on. So when the user hits the down arrow the button below the current button gets highlighted. My issue is that when the user hits the left and right arrows the 'cursor' doesnt move left and right it moves up and down.

The left and right arrows follow the tabindex sequence.

I can't think of a quick fix.

Thanks for your help!
 
Last edited:
VB.NET:
    Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
        Select Case keyData
            Case Keys.Left
                Select Case Me.ActiveControl.Name
                    Case "Button2"
                        Button4.Focus()
                    Case "Button5"
                        Button2.Focus()
                End Select
            Case Keys.Right
                Select Case Me.ActiveControl.Name
                    Case "Button4"
                        Button2.Focus()
                    Case "Button2"
                        Button5.Focus()
                End Select
            Case Keys.Up
                Select Case Me.ActiveControl.Name
                    Case "Button3"
                        Button2.Focus()
                    Case "Button2"
                        Button1.Focus()
                End Select
            Case Keys.Down
                Select Case Me.ActiveControl.Name
                    Case "Button1"
                        Button2.Focus()
                    Case "Button2"
                        Button3.Focus()
                End Select
            Case Else
                Return Me.ProcessDialogKey(keyData)
        End Select
    End Function
 
You can use a DataGridView with Button columns instead, it has that arrow keys functionality too.

With your button grid you can also define a two dimensional array that keeps the button references, then detect the arrow keys and get the corresponding cell reference.
I have a form that needs to have hundreds of buttons
I would most likely go for the DataGridView if there were so many options, also consider filtering options to categories.
 
Thanks for your insight but they are not exactly buttons. its more of a button plus image. So I dont think the datagridview would work. The DataGridView doesnt have a template field does it? Besides the DataGridView is not very pretty and I want this to be heavy on graphics/colors.
 
VB.NET:
    Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
        Select Case keyData
            Case Keys.Left
                Select Case Me.ActiveControl.Name
                    Case "Button2"
                        Button4.Focus()
                    Case "Button5"
                        Button2.Focus()
                End Select
            Case Keys.Right
                Select Case Me.ActiveControl.Name
                    Case "Button4"
                        Button2.Focus()
                    Case "Button2"
                        Button5.Focus()
                End Select
            Case Keys.Up
                Select Case Me.ActiveControl.Name
                    Case "Button3"
                        Button2.Focus()
                    Case "Button2"
                        Button1.Focus()
                End Select
            Case Keys.Down
                Select Case Me.ActiveControl.Name
                    Case "Button1"
                        Button2.Focus()
                    Case "Button2"
                        Button3.Focus()
                End Select
            Case Else
                Return Me.ProcessDialogKey(keyData)
        End Select
    End Function

Well, thanks... My Problem (http://www.vbdotnetforums.com/windows-forms/58017-controling-group-buttons-using-arrow-keys.html) was almost solved.. still working to get it absolutely right... Your code helped a lot!
 
Back
Top