473,666 Members | 1,991 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

best practice for navigating through a table with arrow keys?

PJ6
When I hit an arrow key, I want to be able to change the focus from cell to
cell just like in Excel. I see two ways of doing this. First, emitting in
script a function call in each cell on key down that specifically lists the
ID's of the adjacent controls. The second is to somehow put in some
navigation information into the ID's themselves and then loop through them
on key press to try to calculate which cell to go to next. Which is the
better technique? Are there others that may be better?

TIA,
Paul
Dec 3 '05 #1
2 3785
"PJ6" <no****@nowhere .net> wrote in message
news:Mqlkf.2647 $1y.2159@trnddc 07...
When I hit an arrow key, I want to be able to change the focus from cell to cell just like in Excel. I see two ways of doing this. First, emitting in
script a function call in each cell on key down that specifically lists the ID's of the adjacent controls. The second is to somehow put in some
navigation information into the ID's themselves and then loop through them
on key press to try to calculate which cell to go to next. Which is the
better technique? Are there others that may be better?

TIA,
Paul

Will this help? Watch for word-wrap. Test "as-is".

<html>
<head>
<title>arrows.h tm</title>
<script type="text/javascript">
var b4 = "";
var col = 1;
var row = 1;
document.onkeyu p = function() {
if (window.event) {
var key = window.event.ke yCode;
window.status = key;
if (key == 37) { // left arrow
if (col > 1) col--;
} else if (key == 38) { // up arrow
if (row > 1) row--;
} else if (key == 39) { // right arrow
if (col < 5) col++;
} else if (key == 40) { // down arrow
if (row < 5) row++;
}
bg();
}
}
function bg() {
var rc = "r" + row + "c" + col;
if (b4 == "") b4 = rc;
document.getEle mentById(b4).st yle.backgroundC olor = "white";
document.getEle mentById(rc).st yle.backgroundC olor = "yellow";
b4 = rc;
}
</script>
</head>
<body onload="bg()">
<table border="1" width="500">
<tr height="75">
<th bgcolor="#FFFFF F" width="75"><sup >Use<br>Arrow<b r>Keys</sup></th>
<th bgcolor="#EEEEE E" width="75"><sup >Col 1</sup></th>
<th bgcolor="#EEEEE E" width="75"><sup >Col 2</sup></th>
<th bgcolor="#EEEEE E" width="75"><sup >Col 3</sup></th>
<th bgcolor="#EEEEE E" width="75"><sup >Col 4</sup></th>
<th bgcolor="#EEEEE E" width="75"><sup >Col 5</sup></th>
</tr>
<tr height="75">
<th bgcolor="#EEEEE E"><sup>Row 1</sup></th>
<th id="r1c1">&nbsp ;</th>
<th id="r1c2">&nbsp ;</th>
<th id="r1c3">&nbsp ;</th>
<th id="r1c4">&nbsp ;</th>
<th id="r1c5">&nbsp ;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEE E"><sup>Row 2</sup></th>
<th id="r2c1">&nbsp ;</th>
<th id="r2c2">&nbsp ;</th>
<th id="r2c3">&nbsp ;</th>
<th id="r2c4">&nbsp ;</th>
<th id="r2c5">&nbsp ;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEE E"><sup>Row 3</sup></th>
<th id="r3c1">&nbsp ;</th>
<th id="r3c2">&nbsp ;</th>
<th id="r3c3">&nbsp ;</th>
<th id="r3c4">&nbsp ;</th>
<th id="r3c5">&nbsp ;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEE E"><sup>Row 4</sup></th>
<th id="r4c1">&nbsp ;</th>
<th id="r4c2">&nbsp ;</th>
<th id="r4c3">&nbsp ;</th>
<th id="r4c4">&nbsp ;</th>
<th id="r4c5">&nbsp ;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEE E"><sup>Row 5</sup></th>
<th id="r5c1">&nbsp ;</th>
<th id="r5c2">&nbsp ;</th>
<th id="r5c3">&nbsp ;</th>
<th id="r5c4">&nbsp ;</th>
<th id="r5c5">&nbsp ;</th>
</tr>
</table>
</body>
</html>
Dec 3 '05 #2
PJ6
Yeah that works. I'll go with that variation then.

Thanks,
Paul

"McKirahan" <Ne**@McKirahan .com> wrote in message
news:eb******** ************@co mcast.com...
"PJ6" <no****@nowhere .net> wrote in message
news:Mqlkf.2647 $1y.2159@trnddc 07...
When I hit an arrow key, I want to be able to change the focus from cell

to
cell just like in Excel. I see two ways of doing this. First, emitting in
script a function call in each cell on key down that specifically lists

the
ID's of the adjacent controls. The second is to somehow put in some
navigation information into the ID's themselves and then loop through
them
on key press to try to calculate which cell to go to next. Which is the
better technique? Are there others that may be better?

TIA,
Paul

Will this help? Watch for word-wrap. Test "as-is".

<html>
<head>
<title>arrows.h tm</title>
<script type="text/javascript">
var b4 = "";
var col = 1;
var row = 1;
document.onkeyu p = function() {
if (window.event) {
var key = window.event.ke yCode;
window.status = key;
if (key == 37) { // left arrow
if (col > 1) col--;
} else if (key == 38) { // up arrow
if (row > 1) row--;
} else if (key == 39) { // right arrow
if (col < 5) col++;
} else if (key == 40) { // down arrow
if (row < 5) row++;
}
bg();
}
}
function bg() {
var rc = "r" + row + "c" + col;
if (b4 == "") b4 = rc;
document.getEle mentById(b4).st yle.backgroundC olor = "white";
document.getEle mentById(rc).st yle.backgroundC olor = "yellow";
b4 = rc;
}
</script>
</head>
<body onload="bg()">
<table border="1" width="500">
<tr height="75">
<th bgcolor="#FFFFF F" width="75"><sup >Use<br>Arrow<b r>Keys</sup></th>
<th bgcolor="#EEEEE E" width="75"><sup >Col 1</sup></th>
<th bgcolor="#EEEEE E" width="75"><sup >Col 2</sup></th>
<th bgcolor="#EEEEE E" width="75"><sup >Col 3</sup></th>
<th bgcolor="#EEEEE E" width="75"><sup >Col 4</sup></th>
<th bgcolor="#EEEEE E" width="75"><sup >Col 5</sup></th>
</tr>
<tr height="75">
<th bgcolor="#EEEEE E"><sup>Row 1</sup></th>
<th id="r1c1">&nbsp ;</th>
<th id="r1c2">&nbsp ;</th>
<th id="r1c3">&nbsp ;</th>
<th id="r1c4">&nbsp ;</th>
<th id="r1c5">&nbsp ;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEE E"><sup>Row 2</sup></th>
<th id="r2c1">&nbsp ;</th>
<th id="r2c2">&nbsp ;</th>
<th id="r2c3">&nbsp ;</th>
<th id="r2c4">&nbsp ;</th>
<th id="r2c5">&nbsp ;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEE E"><sup>Row 3</sup></th>
<th id="r3c1">&nbsp ;</th>
<th id="r3c2">&nbsp ;</th>
<th id="r3c3">&nbsp ;</th>
<th id="r3c4">&nbsp ;</th>
<th id="r3c5">&nbsp ;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEE E"><sup>Row 4</sup></th>
<th id="r4c1">&nbsp ;</th>
<th id="r4c2">&nbsp ;</th>
<th id="r4c3">&nbsp ;</th>
<th id="r4c4">&nbsp ;</th>
<th id="r4c5">&nbsp ;</th>
</tr>
<tr height="75">
<th bgcolor="#EEEEE E"><sup>Row 5</sup></th>
<th id="r5c1">&nbsp ;</th>
<th id="r5c2">&nbsp ;</th>
<th id="r5c3">&nbsp ;</th>
<th id="r5c4">&nbsp ;</th>
<th id="r5c5">&nbsp ;</th>
</tr>
</table>
</body>
</html>

Dec 3 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
18211
by: skipc | last post by:
Hi, I am stuck... I've got a popup window that displays a list in table format with links on the bottom to navigate the list <prev> 1 2 3 ... <next> When I demo'd to the users... they immediately asked if they could use the arrow keys and enter key to navigate the list. I think there must be a way to do this, but I can't figure it out.
2
8103
by: Darren Oakey | last post by:
ok - the problem - I made a simple breakout game out of a form, just painting the background - and using keydown for left and right arrow keys to control the bat - worked fine. I then moved all the code into a user control, put it on the form. Now I don't get keydown events when I press an arrow key - on either the form or the usercontrol ?!!!? I suspect somehow the container fucntionality has decided that they are was of migrating...
4
5863
by: Neil Wallace | last post by:
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.
11
2796
by: Rlrcstr | last post by:
How can you detect when an arrow key gets pressed? Doesn't seem to trigger a KeyPress or KeyDown event. Thanks. Jerry
2
5506
by: Vincent | last post by:
Hi, I have a user control that needs to trap the arrow keys to move items around internally. However, using the arrow keys will move the focus to another control on the form hosting the user control. How do I stop this? Vincent.
16
2794
by: Rex | last post by:
Hi All - I have a question that I think MIGHT be of interest to a number of us developers. I am somewhat new to VIsual Studio 2005 but not new to VB. I am looking for ideas about quick and efficient navigating within Visual Studio 2005. Let's say your project (or solution) has dozens of forms and hundreds or even thousands of routines. Two Questions: 1) BUILT-IN to Visual Studio 2005. What ideas do you have to quickly
1
10141
by: Martijn Mulder | last post by:
/* I have problems detecting the Arrow Keys on a User Control. A control derived from System.Windows.Forms.Control neglects 'bare' Arrow Keys but does react on the combination <Altor <Ctrl+ Arrow Key. The code below shows what I mean. How can I cure this? (excuse me for the line breaks) */
0
2915
by: Martijn Mulder | last post by:
/* I override IsInputKey() to direct the Arrow Keys (Cursor Keys) to my custom System.Windows.Forms.Control. But, holding down the Shift-Key prevents the Arrow Keys from coming through. How can I intercept the Arrow Keys when holding down the Shift Key? */
4
3280
by: boopsboops | last post by:
Hi thescripts people, I hope I'm in the right forum for Visual Basic Dotnet (VS 2005). I am trying to make a custom control in which you can nudge a point around using the arrow keys. Actually, the control is meant to be a simple drawing program. To test it out I have put the control on a Windows form which also contains several buttons. I have added a KeyDown event handler to the custom control (see code below). It responds fine to keys...
0
8445
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8871
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.