Add values to cells in Stringgrid

Asked

Viewed 235 times

0

I would like that when I click on a cell of StringGrid I could add a number and press to the side it was jumping from cell to cell, much like the excel, it is possible to do this with this component?

I’ve tried using the keypress, but it doesn’t work very well.

1 answer

2


First, you must enable the option goEditing in Options 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 direction keys, use your ASC II codes:

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.