Recent

Author Topic: Grids questions(Solved)  (Read 526 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1281
Grids questions(Solved)
« on: December 27, 2022, 04:52:21 pm »
A Listbox has a SetFocus - Listbox1.ItemIndex := 0; which places a highlight bar on item 0;

How can you do that with a TStringGrid?
« Last Edit: December 28, 2022, 06:36:52 am by JLWest »
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

howardpc

  • Hero Member
  • *****
  • Posts: 4118
Re: Grids questions
« Reply #1 on: December 27, 2022, 05:45:09 pm »
Code: Pascal  [Select][+][-]
  1. procedure FocusRowCell(aGrid: TStringGrid; aCol, aRow: Integer);
  2. begin
  3.   if Assigned(aGrid) and (aCol < aGrid.ColCount) and (aRow < aGrid.RowCount) then
  4.     begin
  5.       aGrid.Options := aGrid.Options + [goSelectionActive, goDrawFocusSelected];
  6.       aGrid.Row := aRow;
  7.       aGrid.Col := aCol;
  8.     end;
  9. end;

JLWest

  • Hero Member
  • *****
  • Posts: 1281
Re: Grids questions
« Reply #2 on: December 27, 2022, 07:02:51 pm »
@howardpc

Thanks howardpc.

Wonder why they didn't treat this like and event or method. Say

StringGrid1.SetFocus(aRow) or something like that.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

wp

  • Hero Member
  • *****
  • Posts: 10645
Re: Grids questions
« Reply #3 on: December 27, 2022, 07:33:38 pm »
Wonder why they didn't treat this like and event or method. Say

StringGrid1.SetFocus(aRow) or something like that.
StringGrid1.Row := aRow does it. So why an additional method? The other instructions in Howard's code also move the active column (which you did not request) and set the options to enhance the visibility of the active cell (which you can do in the Object Inspector).

JLWest

  • Hero Member
  • *****
  • Posts: 1281
Re: Grids questions
« Reply #4 on: December 27, 2022, 07:47:54 pm »
@wp

I haven't tried howarpc code yet, but I'm pretty sure it works. Now what it does and what I was trying to do is another matter.

What I want is hey stringgrid1 put a blue bar on this row and move the row to the top of the grid or in view at least.

FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

howardpc

  • Hero Member
  • *****
  • Posts: 4118
Re: Grids questions
« Reply #5 on: December 27, 2022, 07:52:45 pm »
Make sure you have goRowHighlight and goRowSelect in the grid's Options property.
You can set the grid's Selection property directly in code.

JLWest

  • Hero Member
  • *****
  • Posts: 1281
Re: Grids questions(Solved)
« Reply #6 on: December 28, 2022, 06:38:38 am »
@howardpc & wp

Works perfect; Of course both of you knew that.

Thanks
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018