I want to tell you about the work I have recently done to the grid - specifically relating to keyboard input. This was prompted mainly by the need to have a good user experience when using editable cells in the grid - which we do not use often but they do occur, for example, in the GL Batch Transaction tab where the user can set Analysis Attribute values for a specific Account Code. I needed to make the keyboard experience both simple and completely generic to all uses of the grid. This is not an attempt just to fix keyboard input for that particular screen. By editing the way the grid accepts keyboard input I am modifying the way that things happen in every grid.
As I looked into the keyboard handler for the grid it was apparent that this was another place where a small bug existed which meant that, although the grid was supposed to handle ENTER, Esc and TAB, none of these keys actually worked (as intended or even at all). So some of what follows has been made to work by fixing the bug and some of it is additional behaviour that I have added.
The first thing to say is that there is an OpenPetra 'rule' that the first column of a grid can not be editable. We need this rule because our grid is always just one control of many or a screen. So the TAB and arrow keys have to be available to move on and off the grid and to move up and down through the grid rows. But this rule should not be difficult to enforce. The first column of a grid will usually be a primary key indicator or a descriptive label (even if it is just a numeric row index). When a row is selected the implicit column is initially the first one and in this condition no editable cells are in edit mode.
I am going to initially describe a scenario that actually does not apply anywhere in OP but is a completely generic case. One day, in the future, we may have this scenario. Afterwards I will show how the generic case collapses to other 'simpler' cases.
[]A grid with 5 rows and 5 columns. Three of the columns are editable. The first and one other are non-editable.[/:m]
[]A grid with 5 rows and 2 columns. Only the second column is editable. (This is a typical case for OP).[/:m]
[]A grid with 5 rows and 5 columns. No columns are editable. (This is the case with all our 'standard' grids.)[/:m][/list:u]
Special Keys
The special keys that are handled by the grid are
[]Arrow Keys and PgUp/PgDn[/:m]
[]ENTER[/:m]
[]Esc(ape)[/:m]
[]TAB[/:m][/list:u]
In addition, OpenPetra handles Home/End, Insert and Delete at the screen level but this is not part of the Grid keyboard handler. It is the behaviour of the above keys that we need to consider here.
Here are the behaviours of these keyboard keys:
When the selected column is the first one
[]Up/Down move the selection up and down[/:m]
[]Left/Right do nothing[/:m]
[]Esc does nothing[/:m]
[]TAB moves you to the next control on the screen (as you would expect)[/:m]
[]ENTER: Here the fun starts! This selects the next editable cell to the right and opens the editor. If there is no editable cell it just ends up back in column 0 where it started. However, if there is an editable cell the cell editor opens and now the keys do the following:
[*]Up/Down moves you up and down inside the comboBox (for example)[/:m]
[]Left/Right move you left and right in the editable area[/:m]
[]Esc cancels the edit on this cell (it really does put the content back to what it was before you started editing) and moves the selection to the next editable cell to the right. If there is no editable cell to the right it wraps back to the first column of the same row and stops (so to the user the row is simply highlighted with no editable control open).[/:m]
[]TAB closes the edit and TAB's you on to the next control on the screen[/:m]
[]ENTER accepts the edit and the selection moves on to the next editable cell in the same row, which now opens. If there is no editable cell to the right, the selection moves back to the first column (so to the user the row is simply highlighted with no editable control open). At this point we are back to where we are when we started at the top of this section.[/:m]
[]SHIFT+ENTER accepts the edit and moves down to the editable cell in the row below but the same column. When you close the edit on the last row the selection moves to the first column (so to the user the row is simply highlighted with no editable control open). Again you are back to the start as far as key handling is concerned.[/:m]
[]CTRL+ENTER accepts the edit and moves down to the first column of the row below. If the row is the last one the selection moves to the first column.[/:m][/list:u][/:m][/list:u]
When you are selecting an item in an edit cell combo box you can type a letter - say 'h' - and then press down arrow and the next matching entry starting with 'h' will be selected (not quite the same as our own combo box but quite similar).
Example 1. A 5 row by 5 column Grid with 3 Editable Columns.
The initial state is that a row is selected and no cells are being edited. When you TAB into the grid from another control the focussed cell is in the first column of the active row. In this state