Recent

Author Topic: StringGrid - How to force a selection of a specific cell  (Read 45226 times)

maKiaveL

  • New Member
  • *
  • Posts: 11
StringGrid - How to force a selection of a specific cell
« on: May 12, 2010, 07:51:56 pm »
How can I force a selection of a specific cell in StringGrid?
For instance, when I run a search I want the first cell to be already selected without having to click.

Thank you very much

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1932
Re: StringGrid - How to force a selection of a specific cell
« Reply #1 on: May 12, 2010, 08:23:44 pm »
This?

Code: [Select]
StringGrid1.Row:=20;
StringGrid1.Col:=5;
StringGrid1.SetFocus;

maKiaveL

  • New Member
  • *
  • Posts: 11
Re: StringGrid - How to force a selection of a specific cell
« Reply #2 on: May 12, 2010, 08:34:27 pm »
No, because that only "set focus" on the cell, doesnt actually select it, since it does not what it's in the OnSelectCell event...
« Last Edit: May 12, 2010, 10:14:52 pm by maKiaveL »

faber

  • Guest
Re: StringGrid - How to force a selection of a specific cell
« Reply #3 on: May 13, 2010, 06:35:09 am »
You can run OnSelectCell manualy
Code: [Select]
StringGrid1.Row:=20;
StringGrid1.Col:=5;
StringGrid1SelectCell(self,20,5,cansel);
StringGrid1.SetFocus;

maKiaveL

  • New Member
  • *
  • Posts: 11
Re: StringGrid - How to force a selection of a specific cell
« Reply #4 on: May 13, 2010, 07:24:35 am »
yeah, that works, thks!

CM630

  • Hero Member
  • *****
  • Posts: 1408
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: StringGrid - How to force a selection of a specific cell
« Reply #5 on: June 12, 2025, 01:50:43 pm »
You can run OnSelectCell manualy
Code: [Select]
StringGrid1.Row:=20;
StringGrid1.Col:=5;
StringGrid1SelectCell(self,20,5,cansel);
StringGrid1.SetFocus;

What is StringGrid1SelectCell(self,20,5,cansel); ?
I tried StringGrid1.SelectCell but there is no SelectCell property.
Лазар 4,0 32 bit (sometimes 64 bit); FPC3,2,2

wp

  • Hero Member
  • *****
  • Posts: 12869
Re: StringGrid - How to force a selection of a specific cell
« Reply #6 on: June 12, 2025, 03:24:12 pm »
What is StringGrid1SelectCell(self,20,5,cansel); ?
The user-provided handler for the OnSelectCell event of the grid.

etrusco

  • New Member
  • *
  • Posts: 11
Re: StringGrid - How to force a selection of a specific cell
« Reply #7 on: June 12, 2025, 05:38:11 pm »
(deleted, wrong instructions)
« Last Edit: June 13, 2025, 05:23:39 pm by etrusco »

CM630

  • Hero Member
  • *****
  • Posts: 1408
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: StringGrid - How to force a selection of a specific cell
« Reply #8 on: June 13, 2025, 07:50:59 am »
I did:
Code: Pascal  [Select][+][-]
  1. procedure TfrmMain.sgFavouritesSelectCell(Sender: TObject; aCol, aRow: Integer; var CanSelect: Boolean);
  2. begin
  3.  
  4. end;
  5.  
  6. procedure TfrmMain.popmFavChangeContentClick(Sender: TObject);
  7. var
  8.   dummy : Boolean;
  9. begin
  10.   sgFavourites.Options := sgFavourites.Options + [goEditing];
  11.   sgFavourites.Col := 1;
  12.   sgFavourites.Row := 11;
  13.   sgFavourites.OnSelectCell(sgFavourites,1,11,dummy);
  14.   sgFavourites.SetFocus;
  15. end;  
I do not see sgFavourites.OnSelectCell(sgFavourites,1,11,dummy); doing anything.
What I need is to set cell [1,11] in editing mode (to start editing it - the cursor is shown, just like as I have clicked on it). Any idea how to do it?

Лазар 4,0 32 bit (sometimes 64 bit); FPC3,2,2

etrusco

  • New Member
  • *
  • Posts: 11
Re: StringGrid - How to force a selection of a specific cell
« Reply #9 on: June 13, 2025, 06:20:30 pm »
This seems enough for me:
Code: Pascal  [Select][+][-]
  1.     sgFavourites.ColRow := Point(1, 11);
  2.     sgFavourites.SetFocus;
  3.     sgFavourites.EditorMode:=true;

You only need sgFavourites.Options := sgFavourites.Options + [goEditing]; if you previously disabled it for some other reason.
You may also want to call sgFavourites.ClearSelections; to tidy the screen.
If you use option goAlwaysShowEditor you don't even need to toggle EditorMode, but there are downsides of course.
AFAICT you shouldn't invoke OnSelectCell. It's already triggered even if the selection is changed non-interactively.

PS. Sorry for the previous unthoughtful reply

CM630

  • Hero Member
  • *****
  • Posts: 1408
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: StringGrid - How to force a selection of a specific cell
« Reply #10 on: June 14, 2025, 11:03:21 pm »
This seems enough for me:
Code: Pascal  [Select][+][-]
  1.     sgFavourites.ColRow := Point(1, 11);
  2.     sgFavourites.SetFocus;
  3.     sgFavourites.EditorMode:=true;
...
I tried it, it seems to do exactly what I want (still I have not tried it in the real app).

Edit: It works in the real app, too.
« Last Edit: June 16, 2025, 02:45:36 pm by CM630 »
Лазар 4,0 32 bit (sometimes 64 bit); FPC3,2,2

 

TinyPortal © 2005-2018