Using Grid control

Started by Jim Short, April 05, 2009, 02:49:23 PM

Previous topic - Next topic

Jim Short

I am looking for information on how to navigate a grid with the keyboard.
Jim Short

owenwengerd

Fred is the grid expert, so hopefully he can provide some insight.
Owen Wengerd (Outside The Box) / ManuSoft

Fred Tomke

Hi, Jim, yes, it's an interesting question. I must say I use grid control very often. But I did not have the idea yet to navigate through the grid using keyboard...
But I allow myself to be persuaded to create a small example. The advantage of the grid (towards the listview) is that there is a OnSelChanged event to get known when you've changed the selection using the keyboard. Unfortunately, the grid has no OnKeyDown and no OnKeyUp-event so you cannot start GridEditing via F2-key as in Windows-Explorer or in Excel. I think about adding a wish on sourceforge...

If you click the row header in a grid, the whole row will be selected. In this case I had no chance anymore to select a single cell unles I click one cell explicitly. Then you can switch between the cells using the cursor keys. The TAB-key is reserved to switch between the controls, not between the cells within the grid.

Jim, let me know if these notes are already helping in this case or what special tasks I should should include in the sample.

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Jim Short

Hi Fred,

Thanks for taking a look at my Grid questions. I wish to use the Grid to display user data that is changed often. This data is presented in the form: Label = Value in column 0 and 1. Column 0 is not enabled just column 1. Efficient data entry would benefit from the following actions.

Picking a cell selects contents
Typing in cell replaces contents
Pressing "Escape" while entering a new value restores previous value
Leaving a cell posts data if cell has been edited
Pressing arrow key moves between cells selecting contents
Pressing "Enter" has the affect of a down arrow key press

Navigating the grid cells by using the arrow keys, typing values and pressing enter or down arrow key is very efficient.

Some windows controls have this behavior built in. I am not that familiar with grid controls.

Thanks,
Jim
Jim Short

Fred Tomke

Hi, Jim, this should also work with the current grid events and methods. After pressing Enter the event EndLabelEdit will be called. In this case do call a SetCurCell with the next row and call a StartCellEdit. The ESC-key can be caught by the form's event CancelClose.

It's a very interesting task. Unfortunately, I have not the time today to build up such a sample. Until 4 p.m. I have to do much business work, until 6 p.m. I have to saw longitudinally the last tree trunks, from 7 to 8 I'm out for a course to train my back. After that I will have to go on my crosstrainer for 2 hours. But in between there is a break and I hope to find the silence to build it.

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Jim Short

I will look into your suggestions.

Thanks,
Jim
Jim Short

Fred Tomke

Hi, Jim, now I have it. Please have a try with the attached example.


  • Click into a cell starts editing immediately.
  • Click into a cell in the first column starts editing the cell in the second column immediately.
  • Press Enter in the editable cell accepts the new value and starts editing the cell in the next row.
  • Press ESC in an editable cell cancels editing and returns to the latest value before editing the cell. The entire row will be selected then so you are able to navigate to the desired line to press enter for editing.
  • Press ESC if no cell is in editable state to cancel the form and to return NIL to discard all changes.
  • Only pressing OK will apply the changes.

Up- and Down-Arrow-keys cannot be triggered in the built-in editbox, I think.

@Owen: Is it possible to trigger the pressed keys in the built-in controls of the grid?

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

owenwengerd

Fred, it's not possible to send keystrokes to the edit control, if that is what you mean.
Owen Wengerd (Outside The Box) / ManuSoft

Fred Tomke

Ok, I must express my self much better:

Please, imagine a cell with CellStyle 6. When this cell turns to editable state, I want to get notified if the user presses the down- or the up-key on keyboard. Unfortunately, there is no OnKeyDown event in the grid. But I'm not sure if the internal editbox of the grid could fire an event at all.

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

owenwengerd

The problem you have is that the edit control may want to process those keystrokes itself. For example, a combo box edit control has its own use for the arrow keys. There could probably be some special case handling for e.g. text box edit controls, but I don't see any good way to handle specific keys in a generic way, because the grid is designed to not know or care about what edit control gets used for cell editing.
Owen Wengerd (Outside The Box) / ManuSoft

Fred Tomke

Thanks Owen, I already feared this.

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Jim Short

Fred,

I tried your example and it worked nice.
This gets data entry moving.
I can live without arrow keys.

Thanks,
Jim
Jim Short

autocart

Sorry to anybody who is bothered by me bringing this back up, but it is important for people like me, using the forum for help by searching in previous topics.

Am I wrong or is the information presented here (above) outdated using OpenDCL 6.0.2.5 ?
I am using a grid in a palette and I just don't get any OnEndLabelEdit events at pressing Enter.
But I noticed that now there are available the desired events KeyDown and KeyUp.
Do I have to use these two events to catch all keystrokes and filter the one out that I want to react to (i.e. Enter or Arrows) and then again change the cell programatically with my own code? Or is there any easier way to start/end cell editing AND navigating in the grid by way of the keyboard?

Thx, Stephan.