By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,214 Members | 2,072 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,214 IT Pros & Developers. It's quick & easy.

Arrow keys to navigate through a set of buttons?

P: n/a
Hi there,

I have an application in which a grid of 100 or more buttons are put on a
form in columns of 10.
All the buttons are within a panel.

They are added in runtime, and so they adopt a sensible tab value.
The tab key moves the focus down the column one by one, and the up and down
arrow keys work well.

What I would like to do, however, is allow the user to use the right/left
arrow keys to jump a column (i.e. current tab value +/- 10), and perhaps the
page down/up keys to move by +/- 50.
Presently these keys do the same as the tab key.

Help!

Cheers

Neil
VB.net Newbie

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Here's an idea. Not tested by any means, but...

Hold a hashtable of all your buttons as you add them at runtime. Add the
tabindex as the key and the control as the button. Then capture the
keypress event and figure out if you need to handle the arrow keys. If the
key pressed is an arrow look at the tabindex of the control, figure out what
the tabindex of the control you want to move to is. Look up the new
tabindex in the hashtable to find the control. Then set the focus onto the
control that is returned from the hashtable.

Something along these lines: (I don't have an editor to test w/ right now)

Dim HT as new HashTable

For ii as integer = 0 to 100
Dim Btn as New Button
'Setup the button and add to form
HT.Item.Add(btn.tabindex, btn)
AddHandler Btn.KeyDown, Address Btn_KeyDownEvent
Next

Private Sub Btn_KeyDownEvent(sender as object, e as Sometypeofeventhandler)
'Check for the key that was press, I think it is e.key or something like
that
dim ButtonPressed as Button = DirectCast(sender, Button)
dim NewIndex as Integer
'if key was right arrow then.....
NewIndex = ButtonPressed.TabIndex +50
'Do checking to make sure it's not too low or too high
dim NewButton as Button = directcast(HT.item(NewIndex), Button)
NewButton.Focus
End Sub

This code is far from perfect, but it should get you going in the right
direction.

good luck
Chris
"Neil Wallace" <ro*******************@virgin.net> wrote in message
news:31*************@uni-berlin.de...
Hi there,

I have an application in which a grid of 100 or more buttons are put on a
form in columns of 10.
All the buttons are within a panel.

They are added in runtime, and so they adopt a sensible tab value.
The tab key moves the focus down the column one by one, and the up and
down arrow keys work well.

What I would like to do, however, is allow the user to use the right/left
arrow keys to jump a column (i.e. current tab value +/- 10), and perhaps
the page down/up keys to move by +/- 50.
Presently these keys do the same as the tab key.

Help!

Cheers

Neil
VB.net Newbie

Nov 21 '05 #2

P: n/a
Here's an idea. Not tested by any means, but...

Hold a hashtable of all your buttons as you add them at runtime. Add the
tabindex as the key and the control as the button. Then capture the
keypress event and figure out if you need to handle the arrow keys. If the
key pressed is an arrow look at the tabindex of the control, figure out what
the tabindex of the control you want to move to is. Look up the new
tabindex in the hashtable to find the control. Then set the focus onto the
control that is returned from the hashtable.

Something along these lines: (I don't have an editor to test w/ right now)

Dim HT as new HashTable

For ii as integer = 0 to 100
Dim Btn as New Button
'Setup the button and add to form
HT.Item.Add(btn.tabindex, btn)
AddHandler Btn.KeyDown, Address Btn_KeyDownEvent
Next

Private Sub Btn_KeyDownEvent(sender as object, e as Sometypeofeventhandler)
'Check for the key that was press, I think it is e.key or something like
that
dim ButtonPressed as Button = DirectCast(sender, Button)
dim NewIndex as Integer
'if key was right arrow then.....
NewIndex = ButtonPressed.TabIndex +50
'Do checking to make sure it's not too low or too high
dim NewButton as Button = directcast(HT.item(NewIndex), Button)
NewButton.Focus
End Sub

This code is far from perfect, but it should get you going in the right
direction.

good luck
Chris
"Neil Wallace" <ro*******************@virgin.net> wrote in message
news:31*************@uni-berlin.de...
Hi there,

I have an application in which a grid of 100 or more buttons are put on a
form in columns of 10.
All the buttons are within a panel.

They are added in runtime, and so they adopt a sensible tab value.
The tab key moves the focus down the column one by one, and the up and
down arrow keys work well.

What I would like to do, however, is allow the user to use the right/left
arrow keys to jump a column (i.e. current tab value +/- 10), and perhaps
the page down/up keys to move by +/- 50.
Presently these keys do the same as the tab key.

Help!

Cheers

Neil
VB.net Newbie

Nov 21 '05 #3

P: n/a
Thanks Chris,
I'll give it a go.

Neil

Chris, Master of All Things Insignificant wrote:
Here's an idea. Not tested by any means, but...

Hold a hashtable of all your buttons as you add them at runtime. Add
the tabindex as the key and the control as the button. Then capture
the keypress event and figure out if you need to handle the arrow
keys. If the key pressed is an arrow look at the tabindex of the
control, figure out what the tabindex of the control you want to move
to is. Look up the new tabindex in the hashtable to find the
control. Then set the focus onto the control that is returned from
the hashtable.
Something along these lines: (I don't have an editor to test w/
right now)
Dim HT as new HashTable

For ii as integer = 0 to 100
Dim Btn as New Button
'Setup the button and add to form
HT.Item.Add(btn.tabindex, btn)
AddHandler Btn.KeyDown, Address Btn_KeyDownEvent
Next

Private Sub Btn_KeyDownEvent(sender as object, e as
Sometypeofeventhandler) 'Check for the key that was press, I think
it is e.key or something like that
dim ButtonPressed as Button = DirectCast(sender, Button)
dim NewIndex as Integer
'if key was right arrow then.....
NewIndex = ButtonPressed.TabIndex +50
'Do checking to make sure it's not too low or too high
dim NewButton as Button = directcast(HT.item(NewIndex), Button)
NewButton.Focus
End Sub

This code is far from perfect, but it should get you going in the
right direction.

good luck
Chris
"Neil Wallace" <ro*******************@virgin.net> wrote in message
news:31*************@uni-berlin.de...
Hi there,

I have an application in which a grid of 100 or more buttons are put
on a form in columns of 10.
All the buttons are within a panel.

They are added in runtime, and so they adopt a sensible tab value.
The tab key moves the focus down the column one by one, and the up
and down arrow keys work well.

What I would like to do, however, is allow the user to use the
right/left arrow keys to jump a column (i.e. current tab value +/-
10), and perhaps the page down/up keys to move by +/- 50.
Presently these keys do the same as the tab key.

Help!

Cheers

Neil
VB.net Newbie

Nov 21 '05 #4

P: n/a
Thanks Chris,
I'll give it a go.

Neil

Chris, Master of All Things Insignificant wrote:
Here's an idea. Not tested by any means, but...

Hold a hashtable of all your buttons as you add them at runtime. Add
the tabindex as the key and the control as the button. Then capture
the keypress event and figure out if you need to handle the arrow
keys. If the key pressed is an arrow look at the tabindex of the
control, figure out what the tabindex of the control you want to move
to is. Look up the new tabindex in the hashtable to find the
control. Then set the focus onto the control that is returned from
the hashtable.
Something along these lines: (I don't have an editor to test w/
right now)
Dim HT as new HashTable

For ii as integer = 0 to 100
Dim Btn as New Button
'Setup the button and add to form
HT.Item.Add(btn.tabindex, btn)
AddHandler Btn.KeyDown, Address Btn_KeyDownEvent
Next

Private Sub Btn_KeyDownEvent(sender as object, e as
Sometypeofeventhandler) 'Check for the key that was press, I think
it is e.key or something like that
dim ButtonPressed as Button = DirectCast(sender, Button)
dim NewIndex as Integer
'if key was right arrow then.....
NewIndex = ButtonPressed.TabIndex +50
'Do checking to make sure it's not too low or too high
dim NewButton as Button = directcast(HT.item(NewIndex), Button)
NewButton.Focus
End Sub

This code is far from perfect, but it should get you going in the
right direction.

good luck
Chris
"Neil Wallace" <ro*******************@virgin.net> wrote in message
news:31*************@uni-berlin.de...
Hi there,

I have an application in which a grid of 100 or more buttons are put
on a form in columns of 10.
All the buttons are within a panel.

They are added in runtime, and so they adopt a sensible tab value.
The tab key moves the focus down the column one by one, and the up
and down arrow keys work well.

What I would like to do, however, is allow the user to use the
right/left arrow keys to jump a column (i.e. current tab value +/-
10), and perhaps the page down/up keys to move by +/- 50.
Presently these keys do the same as the tab key.

Help!

Cheers

Neil
VB.net Newbie

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.