Recent

Author Topic: StringGrid Question  (Read 5471 times)

tintinux

  • Sr. Member
  • ****
  • Posts: 378
    • Gestinux
StringGrid Question
« on: July 07, 2011, 05:16:00 pm »
Hi

After I press RETURN in the last cell of the last row of the grid, I would like to create a new row and go to the first column of it, to go on entry.

The code below does most of the job, BUT after I selected the wanted cell, I have no caret and no focus. I must click with the mouse to be able to enter something and go on.

Anybody knows what I must do to get the focus in the cell, allowing to enter data only with the keyboard ?

I'm using 0.9.30 on Linux. Options of the StringGrid are : AlwaysShowEditor, Editing, DrawFocusSelected.

Thanks for your help !


Code: [Select]
procedure Tform1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);

Var
  R, C : integer ;

begin
  case Key of
    VK_RETURN, VK_TAB :
    begin
      C := StringGrid1.Col ;
      R := StringGrid1.Row;
      if (R = StringGrid1.RowCount-1) and (C = StringGrid1.ColCount-1) then
      begin
        Key := VK_Unknown ;
        StringGrid1.RowCount := StringGrid1.RowCount+1 ;
        StringGrid1.Col := 0 ;
        StringGrid1.Row := R+1 ;
      end;
    end;
  end;
end;   
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: StringGrid Question
« Reply #1 on: July 07, 2011, 05:32:47 pm »
I just tried and it works as you wish (i.e. when I press Enter on the last row&col then row is added, first cell of the new row is focused and I can IMMEDIATELY write).
So maybe there were some improvements in Grids.pas. (I use SVN - see below).
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/

Arbee

  • Full Member
  • ***
  • Posts: 223
Re: StringGrid Question
« Reply #2 on: July 07, 2011, 05:42:34 pm »
Tried this on Windows and there it does work too.  You can start typing text.

Or is your problem that you do not see the caret (admittedly it only shows the focus rectangle), until you actually type the first character?  The caret does show when you first press enter in the new cell.
1.0/2.6.0  XP SP3 & OS X 10.6.8

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: StringGrid Question
« Reply #3 on: July 07, 2011, 05:59:51 pm »
BTW I see there a new option 'goAutoAddRows' . It automaticly adds a row if you press 'VK_DOWN' on the last row (and the last row is not empty).
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/

tintinux

  • Sr. Member
  • ****
  • Posts: 378
    • Gestinux
Re: StringGrid Question
« Reply #4 on: July 09, 2011, 08:43:09 am »
Thanks for your replies.

Yes, it works as expected in 0.9.30 Windows, but not in Linux Gtk2.

I'll have to try to install 0.9.31 and pray :'(

Regards,

Tintinux
Initiator of gestinux, open-source, multi-database and multilingual accounting and billing software made with LAZARUS.

You can help to develop, to make and improve translations, and to provide examples of legal charts and reports from more countries.

 

TinyPortal © 2005-2018