Recent

Author Topic: StringGrid with goRowSelect=true does not go to right cell when I press TAB.  (Read 8645 times)

ademir.uem

  • New Member
  • *
  • Posts: 14
When I use StringGrid with goRowSelect=true when I press Tab it go down only.

Even I select AutoAdvance=aaRight, it never to to Right cell. It is correct?

I am setting goAlwaysShowEditor, goEditing, goTabs to True.

« Last Edit: April 23, 2016, 07:17:53 pm by ademir.uem »

wp

  • Hero Member
  • *****
  • Posts: 11923
Don't use goRowSelect, it always highlights an entire row; to select single cells it must be off.

Then, select the Option goTabs, it makes the grid's active cell advance on the tab key - but you already have this on.

AutoAdvance determines how the active cell advances if you end editing by pressing the ENTER key, aaRight moves it to the right

ademir.uem

  • New Member
  • *
  • Posts: 14
But I want highlights an entire row, so have used goRowSelect for that. What is the other solution for this?

Anyway, when I does not use the  Inplace editor (I replace to another), so it work fine, as I would like.

I don understand.

wp

  • Hero Member
  • *****
  • Posts: 11923
Have the goRowSelect off and fake the rowselect by painting the selected row in the highlight color?
Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
  2.   aState: TGridDrawState);
  3. begin
  4.   if aRow = StringGrid1.Row then
  5.   begin
  6.     if aCol >= StringGrid1.FixedCols then
  7.       StringGrid1.Canvas.Brush.Color := clHighlight
  8.     else
  9.       StringGrid1.Canvas.Brush.Color := clBtnFace;
  10.   end else
  11.   if aRow < StringGrid1.FixedRows then
  12.     StringGrid1.Canvas.Brush.Color := clBtnFace
  13.   else
  14.   if aCol < StringGrid1.FixedCols then
  15.     StringGrid1.canvas.Brush.Color := clBtnFace
  16.   else
  17.     StringGrid1.Canvas.Brush.Color := clWindow;
  18. end;
And you must invalidate the grid in the OnBeforeSelection event because the highlighted cells do not track correctly:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1BeforeSelection(Sender: TObject; aCol, aRow: Integer
  2.   );
  3. begin
  4.   StringGrid1.Invalidate;
  5. end;

ademir.uem

  • New Member
  • *
  • Posts: 14
Thanks WB

Anyway It does not make sense the why goRowSelect does not allow move  to the right when I use aRight.

Why this work fine when I use external editor instead of In-place editor? It does not make sense.

wp

  • Hero Member
  • *****
  • Posts: 11923
Doesn't the attached demo do what you want?
- highlight selected row ("faked rowselect")
- editable cells
- ENTER after edit advances active cell to the right, then to next row
- TAB advances active cell to the right, then to next row

I can't comment on your external editor since I don't know what you are doing there.

ademir.uem

  • New Member
  • *
  • Posts: 14
Your demo works but with a little visual problem. See the attached picture. Especially the column 2 (Nome) when I try edit.

About my external editor,  replace by other, ie. SpinEdit, and I did this

Procedure TFormMain.SpinEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  with StringGrid1 do begin
    if Key in [9,13] then
      EditorMode:=false;
    if Col < ColCount then
       Col := Col + 1
    Else
      Col := 0;
    SetFocus;
  end;
end;

wp

  • Hero Member
  • *****
  • Posts: 11923
Your demo works but with a little visual problem. See the attached picture. Especially the column 2 (Nome) when I try edit.
What is the problem? Looks ok to me...

ademir.uem

  • New Member
  • *
  • Posts: 14
Take a look now. First with your suggestion, second with goRowSelect=true . Problem with canvas, but I do not know how to fix.


wp

  • Hero Member
  • *****
  • Posts: 11923
Try this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.StringGrid1PrepareCanvas(sender: TObject; aCol, aRow: Integer;
  2.   aState: TGridDrawState);
  3. begin
  4.   if aRow = StringGrid1.Row then
  5.   begin
  6.     if aCol = StringGrid1.Col then
  7.       StringGrid1.Canvas.Brush.Color := clWindow
  8.     else
  9.     if aCol >= StringGrid1.FixedCols then
  10.       StringGrid1.Canvas.Brush.Color := clHighlight
  11.     else
  12.       StringGrid1.Canvas.Brush.Color := clBtnFace;
  13.   end else
  14.   if aRow < StringGrid1.FixedRows then
  15.     StringGrid1.Canvas.Brush.Color := clBtnFace
  16.   else
  17.   if aCol < StringGrid1.FixedCols then
  18.     StringGrid1.canvas.Brush.Color := clBtnFace
  19.   else
  20.     StringGrid1.Canvas.Brush.Color := clWindow;
  21. end;

ademir.uem

  • New Member
  • *
  • Posts: 14
The same problem is repeted.  The problem is not the color, but how the select cell is painted. As you can see in my pictures, the cell under edition (selected) is not fulled painted with white color (above and below the text).

wp

  • Hero Member
  • *****
  • Posts: 11923
Sorry, I don't understand. It looks perfect to me - see screenshot (taken with Laz 1.6, using trunk the selected text is offset to the left which is not correct)

[EDIT] I just uploaded a bugreport on cell editor placement in trunk.
« Last Edit: April 24, 2016, 10:36:11 am by wp »

jesusr

  • Sr. Member
  • ****
  • Posts: 484
Also don't forget that the grid has an option goRowHighlight  8)

 

TinyPortal © 2005-2018