Topic: Is There An In-Line TableGrid Edit Method?

Hello,

I was wondering if there is an in-line TableGrid edit method so that I can trigger a selected cell to go into edit mode?

Obviously, using the mouse double click allows you to enter edit mode of a cell but how does one do so using just a keyboard?

Further more, it is common that the F2 key or, in some cases, Shift+F6 keyboard shortcuts allows you to enter edit mode of a cell which is what I am trying to achieve.

I know I can do:

procedure Form1_TableGrid_OnKeyUp (Sender: TObject; var Key: Word; Shift, Alt, Ctrl: boolean);
  begin
    if Key = 71  then // 71 is key code for F2
      <ENTER SELECTED CELL EDIT MODE>
  end;

but as you can see I am missing the <ENTER SELECTED CELL EDIT MODE> part...

Any help or ideas will be appreciated and thank you in advance!

Re: Is There An In-Line TableGrid Edit Method?

If you want to move using "F2" from any place in the form directly to the table to the cell you need, you can use the code:

procedure Form1_OnKeyUp (Sender: TObject; var Key: Word; Shift, Alt, Ctrl: boolean);
begin
  if Key = VK_F2  then
  begin
    Form1.TableGrid1.SetFocus;
    Form1.TableGrid1.SelectedRow := 1;
    Form1.TableGrid1.SelectedColumn := 1;
  end;
end;

Code for the table option goSelectFullRow:=False otherwise the table is in row mode.
You enter the cell editing mode as soon as you start entering a character from the keyboard.
Trying to simply enter a new value into a cell programmatically will not automatically save the result to the database.


As for switching a cell to edit mode using code, it's much more complicated. You need to simulate clicking on the cell. This can be done using the PostMessage function. One of the function parameters is the cell coordinates that need to be calculated. Something like this ).