Recent

Author Topic: TStringGrid: How to move to next column hitting the enter key??  (Read 9971 times)

jshand2010

  • Full Member
  • ***
  • Posts: 236
i have just entered a new cell and put info in that cell, how do i move to the next cell to the right by pressing the enter key??

thanks guys?
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: TStringGrid: How to move to next column hitting the enter key??
« Reply #1 on: May 25, 2013, 12:12:48 am »
If you have [goEditing] in Options then property AutoAdvance := aaRight will do the job (it is default). If you don't use goEditing, you will have to manage it yourself in OnKeyDown or OnKeyUp event. I don't know if StringGrid has some special public method for this but it is easy:
Code: [Select]
if Key = VK_RETURN then
  with (Sender as TStringGrid) do
    Col := Col + 1;
+ skip to next row somehow.  :)
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

jshand2010

  • Full Member
  • ***
  • Posts: 236
Re: TStringGrid: How to move to next column hitting the enter key??
« Reply #2 on: May 25, 2013, 12:27:48 am »
hi there,

i actually found this worked:

procedure Tfproductmanager.sgKeyPress(Sender: TObject; var Key: char);
begin
  if (Key=#13) then begin
    with (Sender as TStringGrid) do begin
      col:=col+1;
    end;
  end;
end;

and i also diabled the goRowSelect as well

thanks heaps
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

Bart

  • Hero Member
  • *****
  • Posts: 5677
    • Bart en Mariska's Webstek
Re: TStringGrid: How to move to next column hitting the enter key??
« Reply #3 on: May 25, 2013, 12:44:04 pm »
procedure Tfproductmanager.sgKeyPress(Sender: TObject; var Key: char);
begin
  if (Key=#13) then begin
    with (Sender as TStringGrid) do begin
      col:=col+1;
    end;
  end;
end;

This will crash on right most column.
AutoAdvance is specifically made for this purpose. No need to re-invent the wheel (and introduce new bugs).

Bart

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: TStringGrid: How to move to next column hitting the enter key??
« Reply #4 on: May 25, 2013, 01:19:58 pm »
@ Bart
I tested and it never crash on right most column (no matter if it is a classic grid or grid made of columns). The AutoAdvance does not work on readonly grid (i.e. when goEditing is False - I don't know if jshand2010 has readonly grid or not). I tested with Laz. trunk.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Bart

  • Hero Member
  • *****
  • Posts: 5677
    • Bart en Mariska's Webstek
Re: TStringGrid: How to move to next column hitting the enter key??
« Reply #5 on: May 25, 2013, 07:01:07 pm »
@ Bart
I tested and it never crash on right most column (no matter if it is a classic grid or grid made of columns).

Hey, that's unexpected...

The AutoAdvance does not work on readonly grid

Yes, that's a valid comment.
Did not think of that.

Bart

 

TinyPortal © 2005-2018