Add values in the cells in the StringGrid

0

I would like that when I click on a cell of StringGrid I could add a number and pressing next to it would jump from cell to cell, much like excel , is it possible to do this with this component? >

I've tried using keypress , but it does not work very well.

    
asked by anonymous 26.09.2017 / 01:01

1 answer

2

First, you must enable the goEditing option in Options of the StringGrid; Then, in the onKeyDown event, add the code (with ENTER ):

if key = 13 then
  begin
    if StringGrid.Col < (StringGrid.ColCount - 1) then StringGrid.Col := StringGrid.Col + 1
    else
      if StringGrid.Row < (StringGrid.RowCount -1) then
        begin
          StringGrid.Col:= StringGrid.FixedCols;
          if StringGrid.Row < (StringGrid.RowCount -1) then StringGrid.Row := StringGrid.Row + 1
        end
      else Perform(WM_NEXTDLGCTL,0,0);
  end;

To do with the arrow keys, use your ASC II codes:

  

37 (left arrow)
  38 (up arrow)
  39 (right arrow)
  40 (down arrow)

Of course, to use with the arrow keys, improved logic will have to be applied, above is just the path to the stones.

    
26.09.2017 / 14:39