Board index » cppbuilder » TStringGrid : Enter should move input-cursor one cell below

TStringGrid : Enter should move input-cursor one cell below

Hi
Do you know a solution for a derrived TStringGrid-component that after
editing in the grid and then pressing the Enter-key, the input-cursor
rectangle is moving down one cell below?
I already tried with the following, but had no success.

Thank you very much in advance.
Tilmann

void __fastcall TTestGrid::KeyDown(WORD &Key, Classes::TShiftState
Shift) {
  if (Key==VK_RETURN) {
     if (EditorMode) {
        SendMessage(Handle, WM_KEYDOWN, VK_RETURN, 0);
      }
      //------------ actuall cell is not the lowest cell
-----------------
      if (Row < RowCount -1) {
        Row= Row +1;
      }
      //------------ actuall cell is the lowest but not in last column
---
      else if (Col < ColCount-1) {
        Col= Col+1;
        Row= FixedRows;
      }
      //------------ case last lowest cell  -> next component
---------------
      else {
        SendMessage(Parent->Handle, WM_NEXTDLGCTL, 0, 0);
      }
    }
   TStringGrid::KeyDown(Key, Shift);

Quote
}

void __fastcall TTestGrid::KeyPress(char &Key) {
  if (Key==VK_RETURN) {
      Key=0;
  }
  //................ others ..................
  TStringGrid::KeyPress(Key);
Quote
}

 

Re:TStringGrid : Enter should move input-cursor one cell below


TK:

Quote
> Do you know a solution for a derrived TStringGrid-component that after
> editing in the grid and then pressing the Enter-key, the input-cursor
> rectangle is moving down one cell below?

I use:

   //now that a move has occured in the structure update the two grids
   yourTStringGrid->Selection=curSelection;//struct of Selection
   bool canSelect=true;
   yourTStringGridSelectCell(Sender,curSelection.TopLeft.X,
                           curSelection.TopLeft.Y,canSelect);
   Application->ProcessMessages();

You should be able to use this just about anywhere in the events functions
You would want OnKeyDown() I assume.

John

--
Use file security for your password and regular applications. Find out how
at http://home.att.net/~special_projects/security.htm
It's Free!

Get The File Editor Professional
http://home.att.net/~special_projects/TheFileEditorProfessional.htm

Join the Shareware Authors Assessment Team see
http://home.att.net/~special_projects/home.htm for more information.

Re:TStringGrid : Enter should move input-cursor one cell below


Dear John

Thank you very much for your answer. I'm little afraid that this is perhaps
not a solution for my problem. Perhaps you can explain it a little more
detailed.

I only want to have a mechanism for the following: User is editing in a
TStringGrid a cell (putting in numbers). Then he presses the Enter-key. Like
in Excel the input-frame is going to next cell and the user is going on
editing numbers.

In onlinehelp SelectCell is described as bool-function for checking whether
the cell can be marked. I only received error messages when I tried  the
suggested method.

Please give me your comment. Thank you very much.
Tilmann

John Borchers schrieb:

Quote
> TK:

> > Do you know a solution for a derrived TStringGrid-component that after
> > editing in the grid and then pressing the Enter-key, the input-cursor
> > rectangle is moving down one cell below?

> I use:

>    //now that a move has occured in the structure update the two grids
>    yourTStringGrid->Selection=curSelection;//struct of Selection
>    bool canSelect=true;
>    yourTStringGridSelectCell(Sender,curSelection.TopLeft.X,
>                            curSelection.TopLeft.Y,canSelect);
>    Application->ProcessMessages();

> You should be able to use this just about anywhere in the events functions
> You would want OnKeyDown() I assume.

> John

> --
> Use file security for your password and regular applications. Find out how
> at http://home.att.net/~special_projects/security.htm
> It's Free!

> Get The File Editor Professional
> http://home.att.net/~special_projects/TheFileEditorProfessional.htm

> Join the Shareware Authors Assessment Team see
> http://home.att.net/~special_projects/home.htm for more information.

Other Threads